views:

54

answers:

1

Hi,

So I have two views, the first have my TableView and the second have my TextField and I want to add a row in my TableView with the text in my TextField.

For the moment I can just add row with

[myTableView addObject:@"Test 1"];
[myTableView addObject:@"Test 2"];
[myTableView addObject:@"Test 3"];

Thanks for your help!

- (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 = [myTableView objectAtIndex:indexPath.row];
cell.textLabel.text = cellValue;

return cell;

}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

return [myTableView count];

}

+1  A: 

I'm not sure exactly what your question is here but I think it will be much clearer if you show us your table view delegate's -tableView:numberOfRowsInSection: and -tableView:cellForRowAtIndexPath: methods. These are the key points where you'll make changes to your table view's behavior, and this is where your answer is likely to start.


Okay. This is a little confusing -- it looks like myTableView is an NSArray? Normally a variable with a name like that would be expected to be a pointer to a table view. But UITableView has neither an -addObject: method nor a -count method.

If that is the case, it looks like you're good (though I really think you should rename that array). You should call one of the -reload* methods on your UITableView to let it know that the data has changed. The simplest is

[ptrToTableView reloadData];

but with a little more work you can get fancier results with -reloadSections:withRowAnimation:.

If this doesn't answer the question, then I'm not sure what the question is. :)

Seamus Campbell
okok i have add my code
Alex
okok thanks but the problem is that my TextField is not linked with my TableView so how can I add a row ?
Alex
and myTableView is a NSMutableArray
Alex