我是 iPhone 应用程序开发的新手。我的要求是:
在我的FirstViewController.xib,我有 2UITextField秒。我想在 in 中显示这两个文本字段的UITableView数据SecondViewController。
我是 iPhone 应用程序开发的新手。我的要求是:
在我的FirstViewController.xib,我有 2UITextField秒。我想在 in 中显示这两个文本字段的UITableView数据SecondViewController。
我希望你有一个按钮可以在 SecondViewController 中导航。点击按钮时,您应该导航到 SecondViewController。
在这里,您可以在点击按钮时将这两个文本字段数据传递到数组中,并将该数组分配给 SecondViewController 的对象。
FirstViewcontroller 按钮点击事件可能如下所示。
-(void) buttonTapped
{  
    SecondViewController *svc = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil] autorelease];
    NSArray *arr = [NSArray arrayWithObjects:textField1.text,textField2.text,nil];
    svc.tableData = arr;
    [self presentModalViewController:svc animated:YES];       
}
在 SecondViewController 中有一个属性 tableData。
@interface SecondViewController : UITableViewController {
    NSArray *tableData; // contains array of data to be displayed in tableview 
}
@property (nonatomic,retain) NSArray *tableData;
@end
您的 tableview 委托方法可能如下所示。
- (NSInteger)numberOfSectionsInTableView:(UITableView *)aTableView {
    // Return the number of sections.
    return 1;
}
- (NSInteger)tableView:(UITableView *)aTableView numberOfRowsInSection:(NSInteger)section {
    // Return the number of rows in the section.
    return [tableData count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellIdentifier = @"CellIdentifier";
    // Dequeue or create a cell of the appropriate type.
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];            
    }
    cell.textLabel.text = [tableData objectAtIndex:indexPath.row];
    return cell;
}
祝你好运。