Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8135143
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T10:19:03+00:00 2026-06-06T10:19:03+00:00

I’m now learning UITableView class on iOS development. I want to implement three sections

  • 0

I’m now learning UITableView class on iOS development. I want to implement three sections in my tableView, but it always crashes when I tap the tabBarItem which contains the tableView. My code is below:

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.title = @"Settings";
        self.tabBarItem.image = [UIImage imageNamed:@"19-gear.png"];
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    NSArray *list1 = [[NSMutableArray alloc] initWithObjects:@"fbfb", @"dfhbfh", @"rtjtj", @"rgrrth", @"grhh", @"tyjtyj", nil];
    NSArray *list2 = [[NSMutableArray alloc] initWithObjects:@"fgngg", @"yjyj", @"rhrht", @"rthfh", @"tjtyjyj", @"fsfsdf", nil];
    NSArray *list3 = [[NSMutableArray alloc] initWithObjects:@"24242", @"24242", @"24242", @"4242", @"4242", @"24242", nil];

    self.array1 = list1;
    self.array2 = list2;
    self.array3 = list3;

    [list1 release];
    [list2 release];
    [list3 release];
}

#pragma mark -
#pragma mark - TableView Data Source Methods

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 3;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    switch (section) {
        case 0:
            return [array1 count];
            break;
        case 1:
            return [array2 count];
            break;
        case 2:
            return [array3 count];
            break;
        default:
            break;
    }
    return 0;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cells = @"Cells";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cells];
    if (cell == nil) 
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cells];
    }
    switch (indexPath.section) {
        case 0:
            cell.textLabel.text = [array1 objectAtIndex:indexPath.row];
            break;
        case 1:
            cell.textLabel.text = [array2 objectAtIndex:indexPath.row];
            break;
        case 2:
            cell.textLabel.text = [array3 objectAtIndex:indexPath.row];
            break;
        default:
            break;
    }
    return cell;

}

the crash log is below:

2012-06-25 23:33:37.694 X-Factor[617:f803] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<SettingsViewController 0x6c912a0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key tableView.'
*** First throw call stack:
(0x13cd022 0x155ecd6 0x13ccee1 0x9c5022 0x936f6b 0x936edb 0x951d50 0x23971a 0x13cedea 0x13387f1 0x23826e 0xde1fc 0xde779 0xde99b 0xfa0a9 0xf9edd 0xf84aa 0xf834f 0xf9e14 0x13cee99 0x1a14e 0x1a0e6 0x2424bd 0x13cee99 0x1a14e 0x1a0e6 0xc0ade 0xc0fa7 0xc0b13 0x244c48 0x13cee99 0x1a14e 0x1a0e6 0xc0ade 0xc0fa7 0xc0266 0x3f3c0 0x3f5e6 0x25dc4 0x19634 0x12b7ef5 0x13a1195 0x1305ff2 0x13048da 0x1303d84 0x1303c9b 0x12b67d8 0x12b688a 0x17626 0x21c2 0x2135)
terminate called throwing an exception(lldb) 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T10:19:06+00:00Added an answer on June 6, 2026 at 10:19 am

    A few points:

    a) I recommend you use ARC rather than manual memory management (as does Apple). ARC is the future of Objective-C and the sooner you start thinking about object graphs rather than retain/release the better.

    b) Don’t use properties in your init code, use the ivars instead (code assumes you synthesise as underscore for your ivars)

    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        _title = @"Settings";
        _tabBarItem.image = [UIImage imageNamed:@"19-gear.png"];
    }
    return self;
    

    c) You need to return the number of sections in the tableview (3) rather than 2 you have entered

    -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
    {
        return 3;
    }
    

    d) Your tableView:numberOfRowsInSection method in not consistent. Put a break statement in each switch statement. i.e.:

    switch (section) {
        case 0:
            return [array1 count];
            break;
        case 1:
            return [array2 count];
            break;
        case 2:
            return [array3 count];
            break;
        default:
            break;
    }
    return 0;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to count how many characters a certain string has in PHP, but
I have a French site that I want to parse, but am running into
i want to parse a xhtml file and display in UITableView. what is the
I want to construct a data frame in an Rcpp function, but when I
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
this is what i have right now Drawing an RSS feed into the php,
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I want use html5's new tag to play a wav file (currently only supported
I am doing a simple coin flipping experiment for class that involves flipping a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.