I am pretty new to Iphone development . so please bear me if I ask some very simple questions.
In my application I have multiple views(i.e. .xib files). On clicking the button on the main view(CouponWebsiteViewController.Xib) the application should load the second view(BrowseList.Xib) which contains a UITable and I have to populate that UITable with some data. I have written following code to populate the data on BrowseList.m file:
- (void) viewDidLoad{
arrayData = [[NSArray alloc] init];
arrayData = [arrayData arrayByAddingObject:@"dfsgdf"];
arrayData = [arrayData arrayByAddingObject:@"aaaaaa"];
self.lblNewScreen.text = [arrayData objectAtIndex:0];
[super viewDidLoad];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [arrayData count];
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier]
autorelease];
}
NSString *cellValue = [arrayData objectAtIndex:indexPath.row];
cell.textLabel.text = cellValue;
[tableView setEditing:YES animated:YES];
return cell;
}
But It is not populating the data in table , when I debug this code I found that it is not executing cellForRowAtIndexPath method but it is debugging numberOfRowsInSection and numberOfSectionsInTableView methods.
But the interesting thing is when I write the same code on the CouponWebsiteViewController.m (i.e. on main view) then it is populating the data in table.
The point is this code is working fine on the main view but it does not work for the other views.
Can any one tell me what am I missing or any other way to populate the UITable on views other than the main view.
Thanks in Advance. Gaurav
I'm not positive but here are some ideas.
viewDidLoad
it's too late. ViewDidLoad
is executed after the data has already been placed in the table. Try putting this code in the initWithStyle method or whatever init
method you have. Or you could even put it int the ViewWillAppear
method, but then make sure to follow this next suggestion.[self.tableView reloadData]
at the end of the viewDidLoad
method. Although that's not as ideal as the first suggestion.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With