[英]Objects not being added to NSMutableArray Objective -C
我試圖將對象簡單地添加到可變數組中,但它們不會插入。 我沒有收到錯誤或任何東西,也無法弄清楚發生了什么。
在我的主要委托文件中,我將數組分成4個單獨的字符串,如下所示。
NSArray *split=[currentParsedCharacterData componentsSeparatedByString:@"|"];
NSLog([split objectAtIndex:3]);
NSString *date=[split objectAtIndex:0];
NSString *venue=[split objectAtIndex:1];
NSString *event=[split objectAtIndex:2];
NSString *city=[split objectAtIndex:3];
我已經找到了字符串值,它們肯定在那里。
接下來,我嘗試將這些字符串值添加到可變數組中
[self.promoTabOptionEvents.dates addObject:date];
[self.promoTabOptionEvents.venues addObject:venue];
[self.promoTabOptionEvents.event addObject:event];
[self.promoTabOptionEvents.city addObject:city];
當我在調試器中檢查數組時,它們為空。 我究竟做錯了什么?
promoTabOptionEvents類看起來像這樣
@interface PromoTabOptionEvents : UIViewController {
NSString *event_headline;
NSMutableArray *dates;
NSMutableArray *venues;
NSMutableArray *event;
NSMutableArray *city;
}
@property(nonatomic,retain)NSString *event_headline;
@property(nonatomic,retain)NSMutableArray *dates;
@property(nonatomic,retain)NSMutableArray *venues;
@property(nonatomic,retain)NSMutableArray *event;
@property(nonatomic,retain)NSMutableArray *city;
-(void)applyLabels;
-(id)initWithTabBar;
@end
#import "PromoTabOptionEvents.h"
@implementation PromoTabOptionEvents
@synthesize event_headline;
@synthesize dates;
@synthesize venues;
@synthesize event;
@synthesize city;
-(id) initWithTabBar {
if ([self init]) {
//this is the label on the tab button itself
//self.title = @"Tab1";
//use whatever image you want and add it to your project
self.tabBarItem.image = [UIImage imageNamed:@"events.png"];
// set the long name shown in the navigation bar
self.navigationItem.title=@"Events";
CGRect bgframe;
bgframe.size.width=320; bgframe.size.height=460;
bgframe.origin.x=0; bgframe.origin.y=0;
UIImage* bgimage = [UIImage imageNamed:@"eventsbig.png"];
UIImageView *imagebgview = [[UIImageView alloc] initWithImage: bgimage];
imagebgview.frame=bgframe;
imagebgview.contentMode=UIViewContentModeScaleAspectFit;
self.view.backgroundColor=[UIColor whiteColor];
[self.view addSubview:imagebgview];
}
return self;
}
您可以在初始化NSMutableArray實例的位置添加代碼嗎? 我認為您可能已經忘記初始化數組,並且addObject調用被吞沒了,沒有任何效果。
您是否在任何地方實例化屬性,如果是,是否已調試通過以驗證情況是否如此? 否則,您可能會將消息發送到nil,這將無效。 或者,您可能在此調用之后進行數組創建,這將使其看起來好像沒有添加。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.