I have an array, I want to save this in UITable, but it is not visible, my code is

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    // Return the number of sections.
    return 1;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    // Return the number of rows in the section.
    return [myArrayNew count];
}


// Customize the appearance of table view cells.
- (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];
    }

    // Configure the cell...
    NSString *cellValue = [myArrayNew objectAtIndex:indexPath.row];
    cell.textLabel.text = cellValue;
    return cell;
}

and this array is having some other array, not single objects,

share|improve this question

72% accept rate
How do you want to display the array of array values in UITableview? – KingofBliss Feb 8 '11 at 5:37
all 3 elements in one row, I want like this – Veer Feb 8 '11 at 5:56
feedback

5 Answers

up vote 0 down vote accepted

Then you should code differently,

[myArrayNew objectAtIndex:indexPath.row]; 

will return an array of objects , not the string.

EDIT:

You can use a sectioned tableview to display array of array.

So that code as follows,

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    // Return the number of sections.
    return [myArrayNew count];
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    // Return the number of rows in the section.
    return [[myArrayNew objectAtIndex:section]count];
}


// Customize the appearance of table view cells.
- (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];
    }

    // Configure the cell...
    NSString *cellValue = [[myArrayNew objectAtIndex:section]objectAtIndex:indexPath.row];
    cell.textLabel.text = cellValue;
    return cell;
}
share|improve this answer
I have two values in an NSMutableArray, but I want to show both values in one single row, then the next two values in next single row, you got it Sir? – Veer Feb 8 '11 at 6:02
error is here that 'section' undeclared, now what is this section is Sir – Veer Feb 8 '11 at 6:11
sorry change it as indexPath.section – KingofBliss Feb 8 '11 at 6:14
error: expected ']' before '.' token this is error, when I put ur code as NSString *cellValue = [[myArrayNew objectAtIndex.section]objectAtIndex:indexPath.row]; – Veer Feb 8 '11 at 6:23
NSString *cellValue = [[myArrayNew objectAtIndex:indexPath.section]objectAtIndex:indexPath.row]; – KingofBliss Feb 8 '11 at 6:59
feedback

you have to store the values in one more array..and the second array object you can assign to a string..

share|improve this answer
Sir I have assigned it to an NSMutableArray, not a NSString, but still problem is same, that I can't show all two values in my NSMutableArray into a single row of my table – Veer Feb 8 '11 at 6:29
1  
This is really a comment, not an answer to the question. Please use "add comment" to leave feedback for the author. – Thor Aug 15 at 12:17
feedback

@Veer use something like this

NSArray *cellArray = [myArrayNew objectAtIndex:indexPath.row];
NSString *cellValue = [cellArray objectAtIndex:indexPath.row];
cell.textLabel.text = cellValue;
return cell;

or something like this. If you show us what type of contents is in myArrayNew then we can can help you more.

EDIT: this just an example not the actual answer.

share|improve this answer
This will crash if cellArray count is less than myArrayNew count. index may become out of bound in this case. – KingofBliss Feb 8 '11 at 5:40
Yes i know, but this is just an example not the actual solution. – Robin Feb 8 '11 at 5:42
hmmmm..ok – KingofBliss Feb 8 '11 at 5:44
feedback

be sure u have set table's datasource and delegate.

and then follow robin's instruction.

thanks,

share|improve this answer
how can I, a bit code can u give me, coz I am not exactly getting you sir – Veer Feb 8 '11 at 6:19
here KingofBliss is 100% right. – fasttrack Feb 8 '11 at 6:19
in.h file @interface ...... : ......<UITableViewDelegate,UITableViewDataSource> in .m file write in viewdidload event. tableview.delegate=self; tableview.datasource=self; – fasttrack Feb 8 '11 at 6:20
@Fassttracks, let me check it, – Veer Feb 8 '11 at 6:25
1  
also set cell textcolor. due that table's background and textcolor looks different. – fasttrack Feb 8 '11 at 6:45
show 1 more comment
feedback

then you try concatenate all the values of array and then assign to label i think this is work

share|improve this answer
This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post - you can always comment on your own posts, and once you have sufficient reputation you will be able to comment on any post. – Jennis Dec 11 at 6:34
feedback

Your Answer

 
or
required, but never shown
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.