ここでは、uitabbarcontrollerからタブを動的に追加および削除しようとしています。3つのタブしかない場合、uitabbarcontrollerから最後のタブを削除する方法
同様に置き換えます。私のアプリの状況は次のとおりです。
ファーストビューには、ログオンし、約
後に正常にログオンし、新たな3つのタブです。最後はMoreと他の2つ。より多くのログオフオプションで
は私が最後のタブを削除し、
が再びログオンし、約持つ最初の二つを交換したいこれを選択した後があります。このようにやって私のコードイムにおけるだから、すなわち(ホームビュー)
........
///AppDelegate.m
(BOOL)アプリケーション:(のUIApplication * )アプリケーションdidFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
//アプリケーション起動後のカスタマイズのためのオーバーライドポイント。
self.window.rootViewController = tabBarCntr; tabBarCntr = [[UITabBarController alloc] init]; LogonViewController * logon = [[LogonViewController alloc] init]; logon.tabBarItem.title = @ "ログオン"; AboutViewController * about = [[AboutViewController alloc] init]; about.tabBarItem.title = @ "About"; tabBarCntr.viewControllers = [NSArray arrayWithObjects:sos1、about、nil]; [ログオンのリリース]; [リリースについて];
[self.window addSubview:tabBarCntr.view];
[self.window makeKeyAndVisible];
self.tabBarController.viewControllers = [NSArrayの
arrayWithObjects:newController1、newController2、より多くの、nilを] tabbarcontrollerする新しいviewcontrollersを設定 }
ログオンに成功した後
と私のIBActionで。
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はあなたが2つの別々のtabBarControllersを使用し、私の意見では、コード
thnksがたくさんありますが、私は最初にサブビューとしてウィンドウに追加すると2つの別のtabbarcontrollerを使用することができます – user968597
appDelegateのタブバーコントローラの2つのインスタンスを作成し、ウィンドウに追加するメソッド。この方法でタブバーを維持することができます。 – vishy
@vishyあなたの提案が私のために働いてくれてありがとう。なぜ私がこの単純な解決法について考えなかったのか、私はまだ驚いています。 – pankaj