0

ok i try my best to explain my problem, I try to create an array after user finish picking a picture from their device

- (void)imagePickerController:(UIImagePickerController *)picker
        didFinishPickingMediaWithInfo:(NSDictionary *)info
        {

        listReceived = [NSArray arrayWithObjects:labelName.text,labelAddress.text,labelAge.text,@"filePicname.png",nil];
       }

and it can repeat several times (more than once), so i try to put it in nsmutablearray

[allListReceived addObject:listReceived];

after that i want to show it all in uitableview, by using custom cell. this is what i try to do:

 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
     static NSString *CellIdentifier = @"TopCell";

        MyCustomCell *cell = (MyCustomCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];


        if (cell == nil) 
        {
            NSArray *topLevelObjects;
            if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
            {
                //topLevelObjects = [[NSBundle mainBundle]loadNibNamed:@"MyCustomCell-iPhone.xib" owner:nil options:nil];
            }else{
                topLevelObjects = [[NSBundle mainBundle]loadNibNamed:@"MyCustomCell-iPad.xib" owner:nil options:nil];
        }
            for (id currentObject in topLevelObjects)
            {
                if ([currentObject isKindOfClass:[UITableViewCell class]])
                {
                    cell = (MyCustomCell *) currentObject;
                    cell.Label1.text = [allListTransfer objectAtIndex:indexPath.row];
                    cell.Label2.text = [allListTransfer objectAtIndex:indexPath.row];
                    cell.Label3.text = [allListTransfer objectAtIndex:indexPath.row];
                    cell.Label4.text = [allListTransfer objectAtIndex:indexPath.row];
                    cell.Label5.text = [allListTransfer objectAtIndex:indexPath.row];
                    break;

                }
            }
        }


        return cell;

    }

Yes i know the nsmutablearray is not used yet, and all the label in custom cell the is the same string as array first index, i read that i have to use nsdictionary. But still no luck in search. If you guys can help me, im really appreciate.

thanks

1
  • 2
    and what's your problem? it doesn't work? have you implemented the other table's datasource and delegate methods? Commented Jul 16, 2013 at 10:35

1 Answer 1

1

Please try this code, It might helps you.

- (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 [allListReceived count];
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 44.0;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"TopCell";
        MyCustomCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if (cell == nil) {
            NSArray* views = [[NSBundle mainBundle]   loadNibNamed:@"MyCustomCell-iPad" owner:nil options:nil];
            for (UIView *view in views) {
                if([view isKindOfClass:[UITableViewCell class]])
                {
                    cell = (MyCustomCell*)view;
                }
            }
        }

        NSString *textStr = [allListReceived objectAtIndex:indexPath.row];

        cell.Label1.text = textStr;
        cell.Label2.text = textStr;
        cell.Label3.text = textStr;
        cell.Label4.text = textStr;
        cell.Label5.text = textStr;

        return cell;

}

If you store NSMutableDictionary then please follow this code :

/* Add Objects To Array */
- (void)imagePickerController:(UIImagePickerController *)picker
        didFinishPickingMediaWithInfo:(NSDictionary *)info
 {
      NSMutableDictionary *dictInfo = [[[NSMutableDictionary alloc] init] autorelease];
     [dictInfo setValue:labelName.text forKey:@"label1"];
     [dictInfo setValue:labelAddress.text forKey:@"label2"];
     [dictInfo setValue:labelAge.text forKey:@"label3"];
     [dictInfo setValue:@"filePicname.png" forKey:@"label4"];

     [allListReceived addObject:dictInfo];
 }


/* Display in UITableView */
NSMutableDictionary *dictInfo = [allListReceived objectAtIndex:indexPath.row];

cell.Label1.text = [dictInfo valueForKey:@"label1"];
cell.Label2.text = [dictInfo valueForKey:@"label2"];
cell.Label3.text = [dictInfo valueForKey:@"label3"];
cell.Label4.text = [dictInfo valueForKey:@"label4"];
cell.Label5.text = [dictInfo valueForKey:@"label5"];

Let me know if you face any problems after trying this code.

Sign up to request clarification or add additional context in comments.

5 Comments

Hi sagarcool89, the erros is Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayI isEqualToString:]: unrecognized selector sent to instance 0xa0cdb20' pointing in cell.Label1.text = textStr.
Error at this line -- NSString *textStr = [allListReceived objectAtIndex:indexPath.row]; Your allListRecieved contains arrays at its indices. To retrieve label text, you need to go further: NSString *textStr = [[allListReceived objectAtIndex:indexPath.row]objectAtIndex:0]; and do likewise to retrive all information.
I suggest you to store your information in NSMutableDictionary and add them to NSMutableArray. and use NSMutableDictionary to display information into the tableview.
Hi sagarcool89 and Puneet, that's what i try to do based on my search in stackoverflow, but ihaven't found any related article to my issue, appreciate if you guys can send me link for me to research.thanks..
check my edited answer , how to use NSMutableDictionary instead of NSString.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.