This is my first iPhone app and first time I'm trying to use a UITableView so please be explicit. What I have is a Tab Navigated Window where on of the views is a list with a title and a series of buttons (add, edit, and remove) at the bottom and a UITableView as the rest of the nib. The TableView's outlet is in my controller and my controller also acts as the delegate and the datasource. Right now I'm circumventing the actual add (which opens a new view allowing the user to fill out a form) and simply adding a new value to my listData NSMutableArray. Now after I add the new Object I call [myTableView reloadData] and the app simply closes without any crash report.
Here is my code
If I remove the [tableView release] from the viewDidLoad method the app no longer exits but nothing happens (the log shows the number of items in listData is increasing however).
Any help would be greatly appreciated.
Here is my code
Code:
- (void)viewDidLoad {
UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectZero style: UITableViewStylePlain];
[tableView setDelegate: self];
[tableView setDataSource: self];
myTableView = tableView;
[tableView release];
self.listData = [[NSMutableArray alloc] initWithObjects: @"Test", @"Hello", @"World", nil];
[super viewDidLoad];
}
Code:
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
Code:
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
NSLog(@"Rows in Section Reached");
return [self.listData count];
}
Code:
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *MyIdentifier = @"MyIdentifier";
NSLog(@"Table view reached");
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
if(cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:MyIdentifier] autorelease];
}
NSLog(cell.description);
cell.textLabel.text = [self.listData objectAtIndex: indexPath.row];
return cell;
}
Code:
-(IBAction)removeFilter: (id) sender {
NSLog(@"Remove Filter Clicked\n");
[self add: @"GoodBye"];
}
Code:
-(void)add:(NSObject *)obj {
NSString *string = [NSString stringWithFormat:@"Number of Items: %d",
[self.listData count]];
NSLog(string);
[self.listData addObject: obj];
string = [NSString stringWithFormat:@"Number of Items: %d",
[self.listData count]];
NSLog(string);
[self.myTableView reloadData];
}
If I remove the [tableView release] from the viewDidLoad method the app no longer exits but nothing happens (the log shows the number of items in listData is increasing however).
Any help would be greatly appreciated.
Last edited: