我是 iPhone 开发者。
我有一个UITableView
,但我无法使它与一个NSMutableArray
.
我已经分配并初始化了我的数组:dataArray
我还连接了我的 tableviewdataSource
和delegate
.
这是我的代码:
SecondViewControllerModal.m
@implementation SecondViewControllerModal
-(IBAction)addArray:(id)sender
{
NSArray *content = [[NSArray alloc] initWithObjects:subjectName.text, setLetter.text, setOrder.text , nil];
SecondViewController *c=[[SecondViewController alloc] init];
[c addToArray:content];
}
...
(addArray
当用户按下按钮时调用)
第二视图控制器.m
-(void)addToArray:(NSArray *)content {
NSString *setSubject = [content objectAtIndex:0];
NSString *setLetter = [content objectAtIndex:1];
NSString *setOrder = [content objectAtIndex:2];
[dataArray addObject:setSubject];
[tableView reloadData];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return [dataArray count];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
[self->tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"Cell"];
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier];
}
// Configure the cell...
cell.textLabel.text = [dataArray objectAtIndex:indexPath.row];
return cell;
}
注意:我正在使用故事板和选项卡式视图应用程序,如果有什么不同,我只需要在 iPad 上运行它。
如果我没有提供足够的详细信息,或者您对代码有任何疑问,请发表评论。
编辑:这就是我的弹出框在 xcode 中的样子: