我正在尝试分配标签,然后创建NSMutableArray
#import "myClass"
static NSString *kC = @"100";
static NSString *kLo = @"110";
@interface MyApp()
@property (strong, nonatomic) NSMutableArray *arrayTag;
@end
@Synthesize arrayTag;
viewDidLoad
中的
arrayTag = [[NSMutableArray alloc] init];
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier];
cell.showsReorderControl = YES;
}
if (indexPath.row == 0)
{
cell.tag = kC;
NSString *cTag = [NSString stringWithFormat:@"%i", cell.tag];
if (![arrayTag containsObject:cTag])
{
[arrayTag addObject:cTag];
}
}
if (indexPath.row == 1)
{
cell.tag = kLo;
NSString *loTag = [NSString stringWithFormat:@"%i", cell.tag];
if (![arrayTag containsObject:loTag])
{
[arrayTag addObject:loTag];
}
}
return cell;
}
至NSLog
:
- (IBAction)doneButton:(id)sender
{
NSLog (@"Number of Objects in Array %i", arrayTag.count);
NSLog (@"Object at Index 0 in Array %@", [arrayTag objectAtIndex:0]);
NSLog (@"Object at Index 1 in Array %@", [arrayTag objectAtIndex:1]);
for (NSString *obj in arrayTag){
NSLog(@"From ArrayTag obj: %@", obj);
}
}
这是Log
2013-07-10 15:46:39.468 MyApp[1013:c07] Number of Objects in Array 2
2013-07-10 15:46:39.469 MyApp[1013:c07] Object at Index 0 in Array 1624272
2013-07-10 15:46:39.469 MyApp[1013:c07] Object at Index 1 in Array 1624256
2013-07-10 15:46:39.469 MyApp[1013:c07] From ArrayTag obj: 1624272
2013-07-10 15:46:39.470 MyApp[1013:c07] From ArrayTag obj: 1624256
问:Object[0] = 100
和Object[1] = 110
的值不应与cell.tag
相匹配吗?为什么会显示1624272和1624256?
答案 0 :(得分:3)
UIView的tag
属性需要NSInteger
,您要为NSString
分配NSString
,或更确切地说,static NSInteger kC = 100;
static NSInteger kLo = 110;
的内存地址。
使用类似的东西:
{{1}}