這裏我試圖動態添加和刪除uitabbarcontroller中的選項卡。如何從uitabbarcontroller中刪除最後一個選項卡(如果只有三個選項卡)
以及替換它們。我的應用程序情況如下。
第一視圖是登錄和約
成功登錄新的3個選項卡後。隨着更多和另外兩個。
更註銷的選擇是有選擇這個後,我想刪除的最後一個標籤和
取代前兩種與再次登錄和版本信息。即(首頁查看)
所以在我的代碼即時通訊做這樣........
///AppDelegate.m
(BOOL)申請:(UIApplication的* )application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
//覆蓋應用程序啓動後自定義的點。
self.window.rootViewController = tabBarCntr; tabBarCntr = [[UITabBarController alloc] init]; LogonViewController * logon = [[LogonViewController alloc] init]; logon.tabBarItem.title = @「Logon」; AboutViewController * about = [[AboutViewController alloc] init]; about.tabBarItem.title = @「About」; tabBarCntr.viewControllers = [NSArray arrayWithObjects:sos1,about,nil]; [登錄發佈]; [關於發佈];
[self.window addSubview:tabBarCntr.view];
[self.window makeKeyAndVisible]; }
在登錄後成功樹立了新viewcontrollers我IBAction爲以tabbarcontroller
self.tabBarController.viewControllers = [NSArray的
arrayWithObjects:newController1,newController2,更多,零];
Now in my loggoff i coding something like.....
NSMutableArray *newArray;
newArray=[NSMutableArray arrayWithArray:self.tabBarController.viewControllers];
[newArray replaceObjectAtIndex:0 withObject:logon];
[newArray replaceObjectAtIndex:1 withObject:about];
[newArray removeLastObject];
self.tabBarController.selectedIndex=0;
[self.tabBarController setViewControllers : newArray];
but my applcation crash here after this ....
can any has solution for this ...
thnx提前。
Paggyyyyy
編輯:NSMutableArray的arrayWithArray增值空間來修復代碼
thnks很多,但我怎樣才能使用兩個單獨的tabbarcontroller,因爲我添加第一個作爲subview到窗口 – user968597 2012-01-10 11:40:25
使appDelegate中的標籤欄控制器的2個實例,在這裏你可以寫一種在窗口上添加的方法。您可以在此方法中維護標籤欄。 – vishy 2012-01-10 11:43:13
@vishy非常感謝你的建議對我也有幫助。我仍然很驚訝,爲什麼我沒有想到這個簡單的解決方案。 – pankaj 2013-03-12 09:15:03