iOS學習筆記2013.06.04

1.CGOffset這個函數的意思是:相對於源矩形原點(左上角的點)沿x軸和y軸偏移 

CGRect detailTextLabelFrame = CGRectOffset(self.textLabel.frame, 0.0f, 25.0f);

2.關於block參數的理解:

- (void)reload:(id)sender {

    [_activityIndicatorViewstartAnimating];

    self.navigationItem.rightBarButtonItem.enabled =NO;

    

    [Tweet publicTimelineTweetsWithBlock:^(NSArray *tweets) {

        if (tweets) {

            _tweets = tweets;

            [self.tableViewreloadData];

        }

        

        [_activityIndicatorViewstopAnimating];

        self.navigationItem.rightBarButtonItem.enabled = YES;

    }];

}

通過這樣直接利用參數值賦給成員變量。主要原因是參考方法publicTimelineTweetsWithBlock:此方法中

+ (void)publicTimelineTweetsWithBlock:(void (^)(NSArray *tweets))block {

    [[AFTwitterAPIClientsharedClient] getPath:@"statuses/public_timeline.json"parameters:[NSDictionarydictionaryWithObject:@"false"forKey:@"include_entities"]success:^(AFHTTPRequestOperation *operation,id JSON) {

        NSMutableArray *mutableTweets = [NSMutableArrayarrayWithCapacity:[JSON count]];

        for (NSDictionary *attributesin JSON) {

            Tweet *tweet = [[Tweetalloc] initWithAttributes:attributes];

            [mutableTweets addObject:tweet];

        }

        if (block) {

            block([NSArray arrayWithArray:mutableTweets]);

        }

    } failure:^(AFHTTPRequestOperation *operation,NSError *error) {        

#if __IPHONE_OS_VERSION_MIN_REQUIRED

        [[[UIAlertViewalloc] initWithTitle:NSLocalizedString(@"Error",nil) message:[error localizedDescription]delegate:nilcancelButtonTitle:nilotherButtonTitles:NSLocalizedString(@"OK",nil), nil] show];

#else

        [[NSAlert alertWithMessageText:NSLocalizedString(@"Error",nil) defaultButton:NSLocalizedString(@"OK",nil) alternateButton:nil otherButton:nil informativeTextWithFormat:[error localizedDescription]] runModal];  

#endif

        if (block) {

            block(nil);

        }

    }];

}

此方法中並沒有對tweets數組的直接賦值,應該類似於數組中自動對應,個人是這麼理解的。

3.對於afnetwork中iOS example,對於post類其實就是對數據的封裝。類似於一個數據源的作用
爲什麼不僅僅定義了一個model原型,還有一個user模型,是因爲一部分數據可以從user裏取出,一部分需要從相應的網絡接口取出。
4.今天學習的滑動菜單,主要是通過對SWRevealViewController類的使用,裏面的動畫,頁面覆蓋已經封裝好了。其實裏面有幾個小問題還是不是很清楚。大體的一個過程:

通過往revealController裏面加入類似於frontviewController和rearviewController。然後以rearviewController裏面引入一些revealviewController的方法。其中在這裏有一個

 //UIViewController類別,獲取父實例

    SWRevealViewController *revelController =self.revealViewController;

self自然對應的是rearviewController,因此兩者之間建立了鏈接。

在UITableView中視圖切換的方法:

/**

 點擊菜單切換視圖

 */

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

{

    [tableView deselectRowAtIndexPath:indexPathanimated:YES];

    

    //UIViewController類別,獲取父實例

    SWRevealViewController *revelController =self.revealViewController;

    NSInteger row = indexPath.row;

    //如果選擇項沒有變化,則直接關閉菜單

    if (row ==_previouslySelectedRow) {

        [revelController revealToggleAnimated:YES];

        return;

    }

    //如果選擇項發生變化,則切換至相應視圖

    _previouslySelectedRow = row;

    UIViewController *viewController = nil;

    switch (row) {  

        case 0:

        {

            MainViewController *firstController = [[MainViewControlleralloc] initWithNibName:@"MainViewController"bundle:nil];

            UINavigationController *nav=[[UINavigationControlleralloc]initWithRootViewController:firstController];

            viewController = nav;

            nav.navigationBar.hidden=YES;

        }

            break;


            case 9:

        {

            PersonCenterViewController *personcenter = [[PersonCenterViewControlleralloc] initWithNibName:@"PersonCenterViewController"bundle:nil];

            UINavigationController *nav=[[UINavigationControlleralloc]initWithRootViewController:personcenter];

            nav.navigationBar.hidden=YES;

          viewController = nav;

            nav.navigationBar.hidden=YES;

        }

            break;

        default:

        {

            PersonCenterViewController *secondController = [[PersonCenterViewControlleralloc] initWithNibName:@"PersonCenterViewController"bundle:nil];

            UINavigationController *nav=[[UINavigationControlleralloc]initWithRootViewController:secondController];

            nav.navigationBar.hidden=YES;

            viewController = nav;

            nav.navigationBar.hidden=YES;

        }

            break;

    }

    //切換視圖(是否帶彈回動畫)

    [revelController setFrontViewController:viewControlleranimated:YES];

    [revelController setFrontViewPosition:FrontViewPositionLeftanimated:YES];

}

5.uipagecontrol中的page計算常用公式:

int page = floor((botScrollView.contentOffset.x - pageWidth / 2) / pageWidth) + 1;

對顏色的切割:

 NSArray *colorArr=[[perDic objectForKey:@"Color"]componentsSeparatedByString:@","];





發佈了11 篇原創文章 · 獲贊 0 · 訪問量 7萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章