any ideas ? some sample code , or some advices will be welcome … thx
// add bank to tableView
-(void)addBankFromList {
if (notInList == nil) {
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Could not be added" message:@"Bank already in list" delegate:self cancelButtonTitle:@"Dismiss" otherButtonTitles:nil, nil];
[alert show];
[alert release];
}
else {
// [banksTableView insertRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:[banks count] inSection:0]] withRowAnimation:UITableViewRowAnimationLeft];
// [banksTableView reloadData];
}
}
// call addBankFromList method when button Add to List is touched .
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
[self addBankFromList];
}
#pragma mark UIPicker Delegate and DataSource methods
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
for (NSString *temp in banksNotInList)
if (temp == [arrayWithBanks objectAtIndex:row]) {
notInList = [[NSMutableString alloc]initWithString:temp];
NSLog(@"%@",temp);
}
else notInList = nil;
}
SOLVED (read first comment)
[appDelegate.banks insertObject:notInList atIndex:[appDelegate.banks count]];
[banksTableView insertRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:[banks count] inSection:0]] withRowAnimation:UITableViewRowAnimationLeft];
[banksTableView reloadData];
It looks like you’ve got the right idea. Logically, you will want to check to see if the object already exists in the table (which you’re already doing). Then if it’s not in, you’ll insert it. That’s where trouble can arise if you’re not too familiar with udpating tableViews. What you’re doing above is the right start. You want to create an indexPath where you’d like to insert the new object, but there are a few steps you want to take before actually inserting the new row. You must have your
numberOfRowsInSectionmatch up with the updated number, so if you are drawing that return from an array, you need to update the array. So assuming you havebanksas your array from which you’re displaying the tableView cells, you would insert the new object into the array at its respecitve position, then callinsertRowsAtIndexPaths:withRowAnimation:. That way when the tableView calls itsdataSourcemethods, it won’t have conflicting results. So in short, you update your data array, then update the tableView. I hope that all makes sense