Iphone 无法从另一个视图从NSMutable数组填充UITableView

Iphone 无法从另一个视图从NSMutable数组填充UITableView,iphone,objective-c,ios,xcode,uitableview,Iphone,Objective C,Ios,Xcode,Uitableview,我有两个VCs,第一个是BooksDetailViewController,它有NSStringmyBookString。另一个是FavBooksViewController,它具有favBookListNSMutableArray。我想从第一个VC传递NSStringmyBookString,将其包含在favBookListNSMutableArray中,然后填充表 我已经包括了@class FavBooksViewController

我有两个VCs,第一个是
BooksDetailViewController
,它有NSString
myBookString
。另一个是
FavBooksViewController
,它具有
favBookList
NSMutableArray。我想从第一个VC传递NSString
myBookString
,将其包含在
favBookList
NSMutableArray中,然后填充表

我已经包括了
@class FavBooksViewControllerBooksDetailViewController.h

导入
#导入
BooksDetailViewController.m中的“FavBooksViewController.h”

BooksDetailViewController.m
中的操作如下所示:

- (IBAction)addToFav:(id)sender {
    FavBooksViewController *mdvc;
    [mdvc.self.favBookList addObject:myBookString];
}
FavBooksViewController.h
中,我有

@interface FavBooksViewController : UIViewController <UITableViewDataSource, UITableViewDelegate>

@property (strong, nonatomic) id delegate;
@property (nonatomic,strong) NSMutableArray *favBookList;
但是我已经把它注释掉了。有了它,我们的UITableView就无法工作。 当然我有这个:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [self.favBookList count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView 
         cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{
           UITableViewCell *cell = [tableView 
                                 dequeueReusableCellWithIdentifier:@"favBooksCell"];

        cell.textLabel.text = [self.favBookList
                               objectAtIndex:indexPath.row];
        return cell;
}
不管怎样,UITableView都是空的,没有单元格,什么都没有。 这里可能有什么错误?我做错了什么?
提前谢谢

您忘记在
cellforrowatinexpath
方法中启动单元格

代码应为:

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

        UITableViewCell *cell = [tableView 
                                 dequeueReusableCellWithIdentifier:identifier];
        if(!cell) {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
        }

        cell.textLabel.text = [self.favBookList
                               objectAtIndex:indexPath.row];
        return cell;
}
试试这个;-)


希望这有帮助。

您忘记在
cellforrowatinexpath
方法中启动单元格

代码应为:

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

        UITableViewCell *cell = [tableView 
                                 dequeueReusableCellWithIdentifier:identifier];
        if(!cell) {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
        }

        cell.textLabel.text = [self.favBookList
                               objectAtIndex:indexPath.row];
        return cell;
}
试试这个;-)


希望这有帮助。

不要将字符串添加到BooksDetailViewController中的数组中,只需将字符串传递到FavBooksViewController中,然后将其添加到FavBooksViewController中的数组中即可

- (IBAction)addToFav:(id)sender {
    FavBooksViewController *mdvc;
    [mdvc setFavBook:myBookString];  
    //favBook is a NSString member object in your FavBooksViewController class

     [self.navigationController pushViewController:mdvc animated:YES];
}

如果可行,请尝试。

不要将字符串添加到BookDetailViewController中的数组中,只需将字符串传递到FavBooksViewController中,然后将其添加到FavBooksViewController中的数组中即可

- (IBAction)addToFav:(id)sender {
    FavBooksViewController *mdvc;
    [mdvc setFavBook:myBookString];  
    //favBook is a NSString member object in your FavBooksViewController class

     [self.navigationController pushViewController:mdvc animated:YES];
}

如果可行,请尝试。

您确定对象已添加到NSMutableArray吗?嘿,SergiusGee,请确保。是否已将tableView与委托/数据源链接?有时我也会遇到:-)@iGranDav是的,我确实有:)你确定对象已添加到NSMutableArray中吗?嘿,SergiusGee,只是为了确定一下。是否已将tableView与委托/数据源链接?有时我也会遇到:-)@iGranDav是的,我当然有:)你必须这么做,但你的数组似乎还是空的。尝试在addToFav方法中删除self。现在应该有[mdvc.favBookList addObject:myBookString];这是我问的第一件事。您确定该对象已添加到NSMutableArray吗?您必须这样做,但您的数组似乎仍然为空。尝试在addToFav方法中删除self。现在应该有[mdvc.favBookList addObject:myBookString];这是我问的第一件事。是否确实已将该对象添加到NSMutableArray?