繁体   English   中英

未将对象添加到NSMutableArray目标-C

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM