Resolved Global Variable (Data Sharing Troubleshoot)

Discussion in 'iOS Programming' started by loon3y, Dec 6, 2011.

  1. loon3y, Dec 6, 2011
    Last edited: Dec 6, 2011

    loon3y macrumors 65816

    loon3y

    Joined:
    Oct 21, 2011
    #1
    i have a global variable "prodTableArray" which is a barcode string that converts itself into an array so it can show the product number in the tableview. as sort of a shopping cart list.


    but it pulls the barcode from the first view controller and it doesn't automatically show up in my tableview unless i rotate it, i also have a similar problem with with a UIImageView on another view controller except that i added a button to retrieve the image.

    but i want to get rid of the button and do it automatically, is this possible?


    heres my table code, how can it automatically update after each barcode scan, i know view willappear works but than the user is going to have to click on another view controller and click back to load the image.


    Code:
    
    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
    {
        ImageStrings* theDataObject = [self theImageClass];
        // Return the number of rows in the section.
        return [theDataObject.prodTableArray count];
    }
    
    
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
         ImageStrings* theDataObject = [self theImageClass];
        static NSString *CellIdentifier = @"Cell";
        
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if (cell == nil) {
            cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
        }
    
        
        cell.textLabel.text = [theDataObject.prodTableArray objectAtIndex:[indexPath row]];
        
    
        
        return cell;
    }
    
    
    
     
  2. admanimal macrumors 68040

    Joined:
    Apr 22, 2005
    #2
    Have you read the UITableView documentation? Do you understand exactly when those two methods are called?
     
  3. loon3y thread starter macrumors 65816

    loon3y

    Joined:
    Oct 21, 2011
    #3
    yes, thank you I've just read it and found the reloading method.

    tyvm
     

Share This Page