UItableviewcontroller cell text label content not displayed

I ve successfully parsed json file in my app but when i tried to display all it in table view its not getting displayed .here is my code.

NSString *urlstr=[NSString stringWithFormat:@"http://minora.p41techdev.net/portal.php"];

NSURL *url=[NSURL URLWithString:urlstr];

NSData *data =[NSData dataWithContentsOfURL:url];

NSError *error;

NSArray *json=(NSMutableArray*) [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];

//NSLog(@"%@",json);
NSDictionary *dict =[NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"a title", @"more data",nil] forKeys:[NSArray arrayWithObjects:@"titleKey",@"dataKey", nil]];


NSLog(@"1");

NSString *integ = [dict valueForKey:@"id"];
NSString *title=[dict valueForKey:@"title"];
NSString *category=[dict valueForKey:@"category"];
NSString *description=[dict valueForKey:@"description"];
NSString *spectitle=[dict valueForKey:@"spectitle"];
NSString *specvalue=[dict valueForKey:@"specvalue"];

NSArray *arr =[NSArray arrayWithObjects:integ,title,category,description,spectitle,specvalue, nil];

[tablearray addObject:arr];    
NSLog(@"%@",tablearray);





}

- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

#pragma mark - Table view data source


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
//#warning Incomplete method implementation.
// Return the number of rows in the section.
return [tablearray count];
NSLog(@"5");

}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];


    cell.textLabel.text=[[tablearray objectAtIndex:indexPath.row] objectAtIndex:1];   


    return cell;

}

  • iOS Swift3 - Convert coordinate
  • App converted to ARC, now getting warnings about my properties
  • How To Customize 'More' Button of UITabBarController?
  • UIPageControl - Change page on click of button
  • Save An Image To Application Documents Folder From UIView On IOS
  • Copying of NSMutableArray from one viewcontroller to another viewcontroller?
  • and my json file looks like this

    [
    {
        "id": "1",
        "category": "New Category1",
        "title": "New Product2",
        "description": "Please type a description1",
        "imgurl": "http://img.ioscake.com/objective-c/wordpress-logo-notext-bg.png",
        "spectitle": "Specification",
        "specvalue": "Value"
    },
    {
        "id": "2",
        "category": "Mobile",
        "title": "Samsung",
        "description": "Please type a description",
        "imgurl": "http://img.ioscake.com/objective-c/wordpress-logo-notext-bg.png",
        "spectitle": "Price",
        "specvalue": "100$"
    }
    ]
    

    Guidance please…

    i’m getting thread issue like this

    2012-07-20 19:36:03.504 tablevc[2253:f803] 1
    2012-07-20 19:36:03.505 tablevc[2253:f803] 2
    2012-07-20 19:36:03.507 tablevc[2253:f803] 4
    2012-07-20 19:36:03.507 tablevc[2253:f803] 3
    2012-07-20 19:36:03.508 tablevc[2253:f803] *** Assertion failure in -[UITableView _createPreparedCellForGlobalRow:withIndexPath:], /SourceCache/UIKit_Sim/UIKit-1914.84/UITableView.m:6061
    2012-07-20 19:36:03.508 tablevc[2253:f803] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath:'
    *** First throw call stack:
    (0x13d2022 0x1563cd6 0x137aa48 0x9b32cb 0xb6d28 0xb73ce 0xa2cbd 0xb16f1 0x5ad21 0x13d3e42    0x1d8a679 0x1d94579 0x1d194f7 0x1d1b3f6 0x1d1aad0 0x13a699e 0x133d640 0x13094c6 0x1308d84  0x1308c9b 0x12bb7d8 0x12bb88a 0x1c626 0x2ae2 0x2a55 0x1)
     terminate called throwing an exception
    

    5 Solutions Collect From Internet About “UItableviewcontroller cell text label content not displayed”

    I don’t see the initialization of tablearray anywhere.

    Add this to your viewDidLoad method:

    tablearray = [[NSMutableArray alloc] init];
    

    I also see that you’re inserting an array within an array. This means that when you need to access the correct data (NSString in your case), you must use the correct index:

    cell.textLabel.text=[[tablearray objectAtIndex:indexPath.row] objectAtIndex:1];   
    

    I used “objectAtIndex:1” because the title string is stored at index 1 in the inner array. A better, more generic approach would be to use NSDictionary. For example:

    NSDictionary *dict =[NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"a title", @"more data",nil] forKeys:[NSArray arrayWithObjects:@"titleKey",@"dataKey"]];
    

    Also, make sure your delegate returns the correct amount of sections for your table.

    Number of sections in tableview is at least one…

      - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
        {
        //#warning Potentially incomplete method implementation.
        // Return the number of sections.
        return 1;//It should be at least one.......
        }
    

    Write the following code in cellForRowAtIndexPath: method. Otherwise you will get error.

    if (cell == nil) {
            cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
        }
    

    I think it will be helpful to you.

    call [tableView reloadData] after you add arr in your table array…

    [tablearray addObject:arr];
    [tableView reloadData]
    NSLog(@"2");
    

    hope it helps

    You should initialize the cell like this:

    - (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] setText:[tablearray objectAtIndex:indexPath.row]];
    
        // Configure the cell...
    
        return cell;
    }
    

    You have tablarray with 1 element. This element is an array containing a few entries.
    Your data source declares only one cell (tablearray count, which is one).

    Your cellForIndexPath method will always look for the first and only the first element in the json array anyway.

    Edit: unrelated, but if a field in your json is not set, you’ll get nil back, and that’ll terminate your array in arrayWithObjects, which will likely cause an out of bounds index down the line.
    Be very careful with this method, it’s very easy to shoot yourself in the foot with it.