網頁

2012年6月29日 星期五

善用pragma mark等相關功能去制定你的標簽...

【環境:xCode4.3.2 】

說明:

一般在攥寫程式時,程式人員通常都會用//來表示注解,但其實還有其他方式可以去很方便的表達注解方式,並且跳到該行。


如下列範例:
1.線段分類
#pragma mark - 
線段分類


2.線段分類+標題
#pragma mark - test

以test為分類的標題


3.其他:"//TODO:"、"//FIXME:"、"//!!!:"、"//???:"
 
#pragma mark - test

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    UIButton *btnDownLoad = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [btnDownLoad setTitle:@"test" forState:UIControlStateNormal];
    [btnDownLoad addTarget:self action:@selector(testDL) forControlEvents:UIControlEventTouchUpInside];
    btnDownLoad.frame = CGRectMake(100, 100, 100, 100);
    [self.view addSubview:btnDownLoad];
    
 // Do any additional setup after loading the view.
}
//FIXME:fix
- (void) testDL
{
    NSURL *url = [NSURL URLWithString:@"http://funwish.net/jhaoheng/testDL.rtf"];
    NSURLRequest *theRequest = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData timeoutInterval:10.0];
    connection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
    connection = nil;
    
}
//TODO:todo
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
    filesize = [NSNumber numberWithUnsignedInteger:[response expectedContentLength]];
}
//???:??????
//!!!:!!!!!!!!!!!!
- (void)connection:(NSURLConnection *)theConnection didReceiveData:(NSData *)recievedData {
    if (data==nil) {
  data = [[NSMutableData alloc] initWithCapacity:2048];
    }
    [data appendData:recievedData];
    
    //NSNumber *resourceLength = [NSNumber numberWithUnsignedInteger:[data length]]; //MAGIC
    //float progress = [resourceLength floatValue] / [filesize floatValue];
    //progressLine.progress = progress;
}

其它相關


As always , if you have any question , feel free to contact me.
有任何問題,請聯絡我

歡迎轉載,請註明出處,感謝。





額外補充:
#pragma 是xcode因應可攜碼的方式編寫的程序,例如告訴編輯器,你下面的code是屬於asm 或者是small。

compiler看到#pragma時如果後面的定義是它不認得的, 它不會理會; 相反的看得懂得compiler就會去執行它.

進階的使用方法-請參考

沒有留言:

張貼留言