2012年5月4日 星期五

2012/05/04 ios sdk4 學習之路002

新增類別 取名為ListViewController 

--我們已經建置了第一頁的畫面 但是點選所建造名稱並不會執行到第二頁面,所以現在所作的事是為了告知電腦,使用者按下按扭之後的事件

--加入類別(#import "ListViewController.h")在#import "RootViewController.h"之下




--更改下列程式的內容- (void)tableView:(UITableView *)tableView 
didSelectRowAtIndexPath:(NSIndexPath *)indexPath {............



- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
ListViewController *detailViewController = [[ListViewController alloc] initWithNibName:@"ListViewController" bundle:nil];
     // ...
     // Pass the selected object to the new view controller.
[self.navigationController pushViewController:detailViewController animated:YES];
[detailViewController release];
 
}


--如以上做法正確已經能看點選左邊箭頭,跑至道第二頁面
--如成功會發現點選進入後會沒有標題告知使用目前剛剛點哪個標題


--再來是編寫點選項目進到第二頁面的標題



--在- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {   底下打


//進入選項的標題
    NSString *title=nil;
    
    
    if (indexPath.row==0
{
title=@"ALL Contacts";
}
else  if (indexPath.row==1
{
title=@"Friends";
}
else if (indexPath.row==2
{
title=@"Work";
}


detailViewController.title=title;




--如此一來點選項進入已經有標題了,但是這樣打太多行了所以簡略程式使用陣列
NSMutableArrray ,  字典類別 NSmutableDictionary 來儲存聯絡人資料

NSArry----NSMutableArry
NSDictionary----NSMutableDictionary
NSSet----NSMutableSet
NSString----NSMutableString


左邊為不可更改類別,右邊的可以





2012/05/03 ios sdk4 學習之路001

建立聯絡人練習




--先匯入三項資料


// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 3;
//顯示三個資料
}

--將return 0 改變成 return 
--代表存三項資料




//讓儲存格顯示三個連絡人名稱
if (indexPath.row==0
{
cell.textLabel.text=@"ALL Contacts";
}
else  if (indexPath.row==1
{
cell.textLabel.text=@"Friends";
}
else if (indexPath.row==2
{
cell.textLabel.text=@"Work";
}
else 
{
NSLog(@"Warning:Error index!!");
}

--在ViewContorller所顯示的字



//設定儲存格右邊展開資料
cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;




- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
self.title=@"Groups";
//改編標題