摘要:
objective-c 使用NSNumber 将int float long等数据类型加入到数组或字典中设置值和取值如下代码: NSNumber *number=[NSNumber numberWithInt:45]; NSLog(@"NSNumber %d",[number intValue]); 阅读全文
摘要:
存储数据时,可以使用字典来存储,这样可以提高搜索速度。以下是创建字典的方法。NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys: @"wtq",@"name1", @"wtm",@"name2", @"wtp",@"name3", nil]; 将字典的值输出来。 NSLog(@"new dictionary is %@",[dic objectForKey:@"name2& 阅读全文
摘要:
通过NSEnumertor来遍历数组元素代码如下:NSArray *array=[NSArray arrayWithObjects: @"one",@"two",@"three",nil]; NSEnumerator *enumerator; enumerator = [array objectEnumerator]; id thing; while (thing=[enumerator nextObject]) { NSLog(@" I have get some value %@",thing); }使用快速遍 阅读全文
摘要:
//可变数组 NSMutableArray *ma = [NSMutableArray arrayWithCapacity:7]; [ma addObject: @"wtq"]; [ma addObject: @"wtp"]; [ma addObject: @"www"]; for (int i = 0; i<[ma count]; i++) { NSLog(@"value %@",[ma objectAtIndex:i]); } [ma addObject:@"wwttqq"]; NSL 阅读全文
摘要:
使用componentsSeparatedByString将字符串分隔成NSArray 数组代码如下: NSString *st = @"wta,wtb,wtc,wtd,wte,wtf,wtg,wth,wti,wtj"; NSArray *sarray = [st componentsSeparatedByString:@","]; for (int i=0; i<[sarray count]; i++) { NSLog(@"value:%@",[sarray objectAtIndex:i]); }使用componentsJo 阅读全文
摘要:
创建uilabel的代码如下- (void)viewDidLoad { [super viewDidLoad]; UILabel *lbWtq = [[[UILabel alloc] initWithFrame:CGRectMake(0, 0, 150, 50)] autorelease]; lbWtq.text=@"this is my name"; //[lbWtq setText:@"text"]; [self.view addSubview:lbWtq]; } 阅读全文