UINavigationBar 的用法

 

//這邊大同小異
    window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    
    /* Create a main view */
    mainView = [[UIView alloc] initWithFrame: [[UIScreen mainScreen] bounds]];

    //開始新增一個NavigationBar 並且把它黏上去
    navbar =  [[UINavigationBar alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 320.0f, 64.0f)];
    [navbar setDelegate: self];
    [navbar pushNavigationItem:[[UINavigationItem alloc] initWithTitle: *"OfflineMaps"] animated : true];
    [mainView addSubview:navbar];

    //開始設計我們的內容 把表單起始化
    list = [[NSMutableArray alloc] init];
	for ( int i = 0; i<4 ; i++)[list addObject:[[NSMutableArray alloc] init]];
        // 這邊分成四個區塊 
	// 0 => Maps
	// 1 => Routes
	// 2 => BookMarks
	// 3 => Info
	
    // 這是用來記錄讀進來的檔案的陣列
    NSMutableArray *maps = [[NSMutableArray alloc] init];
    // Objective-C讀取檔案用的工具 你可以想成 一個檔案總管
    NSFileManager *manager = [NSFileManager defaultManager];
    // Objective-C讀取檔案夾裡面的檔案是透過 NSString 字串的傳遞 這點還滿有趣的
    // 將一個路徑的字串交給 manager 他會把內容物丟到maps這個陣列裡面去
    // stringWithFormat:是讓你用一個模版來輸出字串 %[at]用後面 , 的字串取代
    // 很抱歉 因為論壇系統會擋掉小老鼠[at] 所以詳細的內容還是看source code好了

    [maps addObjectsFromArray:[manager contentsOfDirectoryAtPath:[NSString stringWithFormat:*"%[at]/Media/Maps", NSHomeDirectory()] error:NULL]];
    for (NSString *path in maps) {
        //確認一下這個檔案是不是資料夾 這下面的程式碼是從 Apple Developer的Reference抄來的...
		BOOL isDir;
		if ([manager fileExistsAtPath: [NSString stringWithFormat:*"/var/mobile/Media/Maps/%*",path] isDirectory: &isDir ] && isDir){
			// 如果這個檔案是資料夾 那麼就在辨別 底下是否存在該存在的檔案
			NSString *folder = [NSString stringWithFormat:*"/var/mobile/Media/Maps/%*",path];
			if([manager fileExistsAtPath:[NSString stringWithFormat:*"%*/MapTiles.sqlitedb",folder]]){
			// 好啦 看起來是 那就把這個檔案加入Map那一個區塊
				[[list objectAtIndex: 0 ] addObject: path];
                        // 這邊就是Objective-C最特別的地方 用不完的中括號
			}
		}
		else{
			
			// 如果不是資料夾 那麼他也許是路徑檔 或者是書籤檔
			NSLog(*"Checking Bookmark or Routes"); 
                        // 這是輸出除錯的資料 不過 我自己是很不會看 log 
                        // 底下這段是用來辨別檔案是 Route或是BookMark的
                        // 也許有更漂亮的寫法 但是 我也是新手 我只追求可行
			NSDictionary * plist = [NSMutableDictionary dictionaryWithContentsOfFile:[NSString stringWithFormat:*"/var/mobile/Media/Maps/%*",path]];
			NSString *description = [plist description];
                        
                        //辨別 檔案開頭第六個字元開始的九個字元 形成的字串是
			NSString *checker = [description substringWithRange: NSMakeRange(6,9)];
			// detecting bookmark or Route
			if ([checker isEqualToString:*"Bookmarks"])
			{	//如果是書籤 就加入書籤這一塊
				[[list objectAtIndex: 2] addObject: path];
			}
			else
			{      //如果不是書籤 就加入路徑這一塊
				[[list objectAtIndex: 1] addObject: path];
			}
		}
    }
        //加上一些細部功能
	if([[list objectAtIndex:0] count] != 0){
		[[list objectAtIndex:0] addObject: *"Remove Cache"];
	}
	if([[list objectAtIndex:1] count] != 0){
		[[list objectAtIndex:1] addObject: *"Remove Route"];
	}
	if([[list objectAtIndex:2] count] != 0){
		[[list objectAtIndex:2] addObject: *"Remove Bookmark"];
	}
	[[list objectAtIndex:3] addObject: *"Instruction"];
	
	table = [[UITableView alloc] initWithFrame:CGRectMake(0.0f,60.0f,320.0f,420.0f) style: 1];
	// 1 代表 以群組區分的表單 0 代表 平面的表單
	[mainView addSubview: table];
	[table setDataSource:self];
        [table setDelegate:self];

    [table setEditing:NO animated:NO];
    table.allowsSelectionDuringEditing = YES;

    [table setSeparatorStyle:UITableViewCellSeparatorStyleSingleLine];
    /* Setup window */
    [window makeKeyAndVisible];
    [window addSubview: mainView];

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值