[UIFont 缓存键计数]:发送到实例 IOS 的无法识别的选择器



我尝试使用NSMutableArray,当我在viewDidLoad中使用它时它工作得很好,但我发现了这个问题:

[UIFont 缓存键计数]:发送到实例的无法识别的选择器

当我在其他地方使用它时。

我是最新的,我需要你的帮助

NSMutableArray *MessageList;
@synthesize _table,newwMessage,addMessage;
extern User *user_selected;
- (void)viewDidLoad {
    [super viewDidLoad];
   // MessageList =  [NSMutableArray array];
    MessageList = [[NSMutableArray alloc] init];
    // test web Services
    webServices *web= [[webServices alloc] init];
    AppDelegate *app=  (AppDelegate*)[[UIApplication sharedApplication] delegate];
    [web getConversation:app.user_connect.pk :user_selected.pk completion:^(NSMutableArray * ListMessages) {
        MessageList=ListMessages;
          NSLog(@"haut > %d ",MessageList.count);   // work 
               [_table reloadData];
    }];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString* cellIdentifier = @"messagingCell";
       NSLog(@"haut > %d ",MessageList.count);      // don't work 
    PTSMessagingCell * cell = (PTSMessagingCell*) [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (cell == nil) {
        cell = [[PTSMessagingCell alloc] initMessagingCellWithReuseIdentifier:cellIdentifier];
    }
    cell.contentView.backgroundColor = [UIColor colorWithRed:(254/255.0) green:(168/255.0) blue:(198/255.0) alpha:1] ;;
    [self configureCell:cell atIndexPath:indexPath];
    return cell;
}

你可能正在使用ARC。因此,您的对象会在 viewDidLoad 结束时自动释放。由于您的对象被释放(但未无效),内存放置已被重复使用,并且您指向它。但那时它是另一个对象

要纠正这一点,您必须在数组上添加一个强属性

@property (nonatomic, strong) NSMutableArray *messageList

您可以将其放在头文件中,也可以放在 .m 的私有类别中

然后像这样使用你的财产:

self.messageList = [[NSMutableArray alloc] init];

PS:命名约定说最好以小写字母开头 ;) !

最新更新