http://istarelworkshop.com/2011/06/17/using_the_tbxml_library
http://stackoverflow.com/questions/5406424/iphone-tbxml-looping-and-parsing-data
http://ntt.cc/2010/09/05/50-open-source-iphone-apps-for-iphone-developers.html
2011年11月1日 星期二
NSString 是 Object C 中常用的類。在這裡,在網路上搜集整理一些關於 NSString 的操作供參考:
- 添加 '@' 在字串前變成 NSString
NSString \*t = @"test"
- 連接
字串連接有三種方法:
NSString *string1; NSString\* string2;
1. NString *compose = [NSString initWithFormat:@"%@,%@", string1, string2 ];
2. NString *compose = [string1 stringByAppendingString:string2];
3 . NString *compose = [string stringByAppendingFormat:@"%@,%@",string1, string2];
其中 format 的格式為:
'%@' 是格式化 NSString 類型
%d, %D, %i 是格式化 32位元有符號整數 (int)
具體見參考手冊
- Format (initWithFormat & stringWithFormat)
NSString *string = [[NSString alloc] initWithFormat:@"%@", otherString];
label.text = string;
[string release]; //使用alloc不要忘記release掉!
myStr = [NSString stringWithFormat:@"%@", otherStr2];
- 轉換(從別的型態轉至NSString)
int 到 NSString: [NSString stringWithFormat:@"%d", myInt];
NSInteger 到 NSString: [NSString stringWithFormat:@"%d", [myNSInt intValue]];
- 比對(兩個字串比對)
if ([textField.text isEqualToString: @""]) {
textField.text = @"0";
}
不是用 textField.text! == @""; 來比對喔! complier會過,但執行不理你!
不同button給不同的tag, 可呼叫同一個action。
myBtn1.tag = 1
[myBtn addTarget...];
myBtn2.tag = 2
[myBtn2 addTarget...];
- (void)clickTest:(id)sender
{
UIButton* btn = sender;
switch(btn.tag)
{
case 1:
//
break;
case 2:
//
break;
}
}
[myBtn addTarget...];
myBtn2.tag = 2
[myBtn2 addTarget...];
- (void)clickTest:(id)sender
{
UIButton* btn = sender;
switch(btn.tag)
{
case 1:
//
break;
case 2:
//
break;
}
}
2011年10月29日 星期六
Objective C 如何使用Dictionary
//create the dictionary
NSMutableDictionary *dictionary = [[NSMutableDictionary alloc] init];
//add keyed data
[dictionary setObject:@"Orange" forKey:@"Peggy"];
[dictionary setObject:@"Purple" forKey:@"Landy"];
[dictionary setObject:@"Red" forKey:@"Ula"];
//write out "Orange" to the log
NSLog(@"%@", [dictionary objectForKey:@"Peggy"]);
// values in foreach loop -1
NSLog(@"%@", dictionary );
NSArray *keys = [dictionary allKeys];
for (NSString *key in keys) {
NSLog(@"%@ is %@",key, [dictionary objectForKey:key]);
}
//values in foreach loop -2
for (id theKey in dictionary ) {
id anObject = [[aDictionary objectForKey:theKey] retain];
}
//release the dictionary
[dictionary release];
NSMutableDictionary *dictionary = [[NSMutableDictionary alloc] init];
//add keyed data
[dictionary setObject:@"Orange" forKey:@"Peggy"];
[dictionary setObject:@"Purple" forKey:@"Landy"];
[dictionary setObject:@"Red" forKey:@"Ula"];
//write out "Orange" to the log
NSLog(@"%@", [dictionary objectForKey:@"Peggy"]);
// values in foreach loop -1
NSLog(@"%@", dictionary );
NSArray *keys = [dictionary allKeys];
for (NSString *key in keys) {
NSLog(@"%@ is %@",key, [dictionary objectForKey:key]);
}
//values in foreach loop -2
for (id theKey in dictionary ) {
id anObject = [[aDictionary objectForKey:theKey] retain];
}
//release the dictionary
[dictionary release];
2011年10月28日 星期五
convert NSString value to NSData
http://stackoverflow.com/questions/901357/nsstring-to-nsdata
(1)
(2)
(1)
NSString* str= @"teststring";
NSData* data=[str dataUsingEncoding:NSUTF8StringEncoding];(2)
NSString* myString= @"testing";
NSData* data=[myString dataUsingEncoding: [NSString defaultCStringEncoding] ];(3)NSData* data = [yourString dataUsingEncoding:NSUTF8StringEncoding]; data = [data subdataWithRange:NSMakeRange(0, [data length] - 1)];
訂閱:
文章 (Atom)