相关疑难解决方法(0)

NSMutableArray addObject不起作用

NSMutableArray *categories在我的视图控制器.h文件中声明了一个,并为它声明了一个属性.

在我的.m文件中委托的parser:foundCharacters:方法中NSXMLParser,我有这个代码:

-(void)parser:(NSXMLParser *) parser foundCharacters:(NSString *)string  
{  
    if (elementFound)  
    {  
        element = string;  
        [self.categories addObject:element];  
    }  
}
Run Code Online (Sandbox Code Playgroud)

但是当我[self.categories addObject:element]在调试模式中踩到它后将鼠标悬停在线上时,XCode告诉我大小为0x0,0个对象.我的XML文件中有3个元素,因此数组中应包含3个项目.

我错过了一些非常明显的东西,我无法弄清楚是什么.

objective-c nsmutablearray

54
推荐指数
2
解决办法
7万
查看次数

无法将对象添加到NSMutableArray数组

@interface SimataDetailViewController () 

@property Simata *simata;

@property (nonatomic, copy) NSMutableArray *simataList;

@end

@implementation SimataDetailViewController

@synthesize simataDataController=_simataDataController;
@synthesize category=_category;
@synthesize simata=_simata;
@synthesize simataList=_simataList;

#pragma mark - Managing the detail item



- (void) getSimataForCategory: (NSString *) inputCategory {

    unsigned count = [self.simataDataController.masterList2 count];


    while (count--) {

        if ([[[self.simataDataController objectSimataInListAtIndex:count] categoryCode] isEqual:inputCategory]){
            self.simata= [self.simataDataController objectSimataInListAtIndex:count];

            [self.simataList addObject:self.simata];                       
        }

    }

    NSLog(@"count, %u", [self.simataList count]);


}
Run Code Online (Sandbox Code Playgroud)

您好,这是我的第一篇文章,请耐心等待.

我试图将对象添加self.simata到数组,self.simataList但数组保持零对象.对象self.simata不是nil,我没有任何错误.

我究竟做错了什么?

objective-c nsmutablearray

4
推荐指数
1
解决办法
1626
查看次数

NSMutableArray不添加对象

我认为,我正在做一个非常基本的错误,但我正在使用一个NSMutableArray,这不知何故不添加对象,我发送它的方式.我有一个属性(和合成)

@property (nonatomic, strong) NSMutableArray *kpiStorage;
Run Code Online (Sandbox Code Playgroud)

然后:

ExampleObject *obj1 = [[ExampleObject alloc] init];
[kpiStorage addObject:obj1];
ExampleObject *obj2 =  [[ExampleObject alloc] init];
[kpiStorage addObject:obj2];

NSLog(@"kpistorage has:%@", [kpiStorage count]);
Run Code Online (Sandbox Code Playgroud)

并且总是在控制台中返回(null).我有什么误会?

objective-c count nsmutablearray ios

3
推荐指数
1
解决办法
1万
查看次数

NSMutableArray addObject不影响计数?

任何人都可以告诉我为什么登录[self.giftees count]仍然返回0,即使我正在添加对象?

标题:

#import <UIKit/UIKit.h>

@interface Test2AppDelegate : NSObject <UIApplicationDelegate>  
{
    UIWindow *window;
    NSMutableArray *giftees;
}

@property (nonatomic, retain) UIWindow *window;
@property (nonatomic, retain) NSMutableArray *giftees;

@end
Run Code Online (Sandbox Code Playgroud)

从didFinishLaunchingWithOptions调用:

- (void)bootstrapGiftees
{
    NSArray *gifteeNames = [NSArray arrayWithObjects:@"Jesse",,nil];

    for (NSString *gifteeName in gifteeNames)
    {
        GifteeModel *g = [[GifteeModel alloc] init];
        g.name = gifteeName;

        [self.giftees addObject:g];
        NSLog(@"giftees count = %d", [self.giftees count]);
        [g release];
}
}
Run Code Online (Sandbox Code Playgroud)

objective-c nsmutablearray

0
推荐指数
1
解决办法
1394
查看次数

标签 统计

nsmutablearray ×4

objective-c ×4

count ×1

ios ×1