0

わかりました私は自分の問題を説明するために最善を尽くします.ユーザーがデバイスから写真を選択し終わった後、配列を作成しようとします

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

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

そしてそれは数回(複数回)繰り返すことができるので、nsmutablearrayに入れようとします

[allListReceived addObject:listReceived];

その後、カスタムセルを使用して、uitableview ですべて表示したいと思います。これは私がやろうとしていることです:

 - (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;

    }

はい、nsmutablearray がまだ使用されていないことはわかっています。カスタム セル内のすべてのラベルは、配列の最初のインデックスと同じ文字列です。nsdictionary を使用する必要があることを読みました。しかし、検索ではまだ運がありません。皆さんが私を助けることができれば、本当に感謝しています。

ありがとう

4

1 に答える 1

1

このコードを試してみてください。役立つかもしれません。

- (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;

}

NSMutableDictionary を保存する場合は、次のコードに従ってください。

/* 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"];

このコードを試した後に問題が発生した場合はお知らせください。

于 2013-07-16T10:40:02.543 に答える