Reputation: 2749
I'm trying to learn iOS development and I cant figure this out! EXAMPLE: Using Xcode 4.2 I make a new "Single-View Application". I then add a table view to the view. I then go under File>New>New File and create a UIViewControllerSubclass that's a subclass of UITableViewController. I then click on my the only view-controller in storyboard, go under the identity inspector and change its class to the one I just made. Then I link the table views data source and delegate to the view-controller. I go open the .m file from the class I made and set its number of sections to 1, number of rows in section to 3, and "Configure" the cells to say "Hello"(cell.textlabel.text=@"Hello";). When I run the program I get a error saying "SIGABRT" but there are no warnings or errors at all in the program. What am I doing wrong?
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 5;
}
- (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];
}
cell.textLabel.text=@"cell1";
return cell;
}
Upvotes: 0
Views: 2502
Reputation: 15722
When you first create your project, go to the storyboard and delete the generic View Controller scene that XCode creates for you by default. Then drag a Table View Controller object onto your storyboard from the Object Browser, and in the Identity Inspector change the Class to your custom class. (Note that the table view controller you dragged out will already contain the tableView and prototype cell you need.) Connect the datasource & delegate properties as you did before, and implement the code in your custom class .m file as above.
After that you will not see the error.
Upvotes: 2
Reputation: 1
Try and enable NSZOMBIE to help you pinpoint your problem. To do so, double-click on your executable in the Executables group of your Xcode project. Click the Arguments tab. In the "Variables to be set in the environment:" section, make a variable called "NSZombieEnabled" and set its value to "YES".
Upvotes: 0