I'm new in the iPhone development.
I'm trying to make a record of items in a table view, but i'm having problems with the reloadData, this is terminating with crash: "Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[UIView reloadData]: unrecognized selector sent to instance 0x470a480'"
The error means that there is no reloadData method in vView. From the code you presented I can't tell what class vView is an instance of but, based on the error, it appears to be UIView. I think it should be UITableView. reloadData is a method in that class.
In the second set of code you correctly send the reloadData message to an instance of UITableView - that's why it works.
The error means that there is no reloadData method in vView. From the code you presented I can't tell what class vView is an instance of but, based on the error, it appears to be UIView. I think it should be UITableView. reloadData is a method in that class.
In the second set of code you correctly send the reloadData message to an instance of UITableView - that's why it works.
Did you remember to make your class conform to UIAlertViewDelegate? Your initial class declaration (in your header file, YourViewCobtroller.h" should look something like this:
That does not work because you never assigned your varible to an uitableview object.
Since you are using a uitableviewcontroller try
[self.tableview reloadData];
__________________
Haters gonna Hate
Likers gonna Like
Thank Bertrand21, stopped the crash but tableview is not being updated after entering with a new item.
Method cellForRowAtIndexPath which redraws the tableview, is not fired after execute reloadData.
Thank Bertrand21, stopped the crash but tableview is not being updated after entering with a new item.
Method cellForRowAtIndexPath which redraws the tableview, is not fired after execute reloadData.
Code:
[self.tableView reloadData];
Where are you adding a new "item"? Are you sure your adding it to the same tableview datasource? The system will only reload the data if it seems necessary. So if you are not adding an item to the datasource it will not work.
__________________
Haters gonna Hate
Likers gonna Like
Where are you adding a new "item"? Are you sure your adding it to the same tableview datasource? The system will only reload the data if it seems necessary. So if you are not adding an item to the datasource it will not work.
Hi, yeah I'm sure of it.
I put a reloadData (blue line below) in this method, just for test:
Code:
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle
forRowAtIndexPath:(NSIndexPath *)indexPath
{
// If row is deleted, remove it from the list.
if (editingStyle == UITableViewCellEditingStyleDelete)
{
if (indexPath.row > 0)
{
[datController RemoveData:indexPath.row-1];
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]
withRowAnimation:UITableViewRowAnimationFade];
}
}
else if(editingStyle == UITableViewCellEditingStyleInsert)
{
UIAlertView *myAlertView = [[UIAlertView alloc] initWithTitle:@"Enter the item." message:@"" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Ok",nil];
fldItem = [[UITextField alloc] initWithFrame:CGRectMake(12.0, 45.0, 260.0, 25.0)];
[fldItem setBackgroundColor:[UIColor whiteColor]];
[myAlertView addSubview:fldItem];
[tableView reloadData];
[myAlertView show];
[myAlertView release];
}
}
and when I select again the option "Add items...", it shows the tableview updated with the item I that added previously.
The problem is specific to reloadData after entering the item.
For some unknow reason, this method is not fired in the second reloadData:
Code:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
//Try to get rusable (rusable) cell
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CellIdentifier"];
if (cell == nil)
{
//If not possible create a new cell
cell = [[[UITableViewCell alloc] initWithFrame:CGRectMake(0,0,0,0) reuseIdentifier:@"CellIdentifier"] autorelease];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
// Get the string to display and set the value in the cell
if(indexPath.row == 0)
{
cell.textLabel.text = @"Add items...";
}
else
{
cell.textLabel.text = [datController ListData:indexPath.row-1];
}
return cell;
}
Ahh I see your problem. You are showing an alertview and then reloading your table.*
What you need to do is do your reload your table using the delegate method from your alertview. So when the user presses save it updates your table.*