2011-08-11 31 views
0

我有一個視圖,其中有一個標籤欄和一個表格視圖。在某個時候,我稱之爲模態視圖,當我忽略它時,原始視圖似乎伸展或向下移動,因爲背景圖像較低,並且表視圖較長,直到最後一個單元超出幀的位置。解散modalview後UITableView和背景圖像向下移動

我所說的模態視圖從tableView:didSelectRowAtIndexPath

- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    NSMutableDictionary *row  = [[[[self.productDetails valueForKey:@"sections"] objectAtIndex:indexPath.section] valueForKey:@"rows"] objectAtIndex:indexPath.row]; 
    NSMutableDictionary *post  = [self.productDetails valueForKey:@"post"]; 
    if ([[row valueForKey:@"type"] isEqualToString:@"pick"]) 
    { 
     self.xPicker    = nil; 
     self.xPicker.options  = nil; 
     self.pickerOptions   = nil; 
     self.xPicker    = [[[TablePicker alloc] initWithNibName:@"TablePicker" bundle:[NSBundle mainBundle]] autorelease]; 
     NSMutableDictionary *newPicker = [[[NSMutableDictionary alloc] init] autorelease]; 
     [newPicker setValue:[NSString stringWithFormat:@"%d", indexPath.section] forKey:@"section"]; 
     [newPicker setValue:[NSString stringWithFormat:@"%d", indexPath.row] forKey:@"row"]; 
     [newPicker setValue:[row valueForKey:@"options"] forKey:@"options"]; 
     [newPicker setValue:[row valueForKey:@"value"] forKey:@"value"]; 
     self.xPicker.options  = [NSMutableDictionary dictionaryWithDictionary:newPicker]; 
     self.pickerOptions   = [NSDictionary dictionaryWithDictionary:newPicker]; 
     self.xPicker.view.frame  = self.view.bounds; 
     [self presentModalViewController:self.xPicker animated:YES]; 
    } 
} 

裏面的模態視圖控制器,我做一些東西,然後觸發一個通知,讓家長控制器知道它的確定將其關閉。這部分感覺不對,但我偶爾得到一個錯誤,當我有模式的看法呼叫:

[self.parentViewController dismissModalViewControllerAnimated:YES]; 

不管怎麼說,代碼塊,我解僱模態視圖如下:

- (void) reloadCell 
{ 
    [self dismissModalViewControllerAnimated:YES]; 
    if (self.xPicker.choice != nil) 
    { 
     NSDictionary *choice  = self.xPicker.choice; 
     NSMutableDictionary *row = [[[[self.productDetails valueForKey:@"sections"] objectAtIndex:[[choice valueForKey:@"section"] intValue]] valueForKey:@"rows"] objectAtIndex:[[choice valueForKey:@"row"] intValue]]; 
     [row setObject:[choice valueForKey:@"value"] forKey:@"value"]; 
     [[self.productDetails valueForKey:@"post"] setObject:[choice valueForKey:@"value"] forKey:[row valueForKey:@"key"]]; 
     Request *xReq    = [[[Request alloc] init] autorelease]; 
     [NSThread detachNewThreadSelector:@selector(updateOrderFromProductDetails:) toTarget:xReq withObject:[self.productDetails valueForKey:@"post"]]; 
     self.xPicker    = nil; 
    } 
} 

我不知道它是否相關,但是我發現有趣的是,當我在設備處於橫向模式時展示這個模式控制器時,視圖變得不可思議。

有誰知道如何解決這個問題?

編輯:經過一番搜索,看來,這兩個問題是相關的,有我的當前視圖控制器是另一個視圖控制器的子視圖做,但不是通過導航控制器。

據我瞭解,我決定不使用導航控制器會讓我的視圖堆棧產生混淆。我有一種感覺會回來咬我的屁股。

不幸的是,我似乎無法找到解決我的問題的任何地方。

+0

表視圖的框架必定有問題。你能發佈你的整個實現(.m)文件嗎? –

+0

你有任何導航控制器或工具欄? –

+0

因此,當你調用[myTableView reloadData]框架會變得混亂(意味着它超出了你的內容視圖的底部)? –

回答

0

好的,我有一個解決這個問題的方法。

而是有我的當前視圖控制器的呼叫presentModalViewController的,我把它從的appDelegate tabBarController像這樣:

[[(myAppDelegate *)[[UIApplication sharedApplication] delegate] tabBarController] presentModalViewController:self.myModalViewController animated:YES]; 

這仍然感覺有點哈克,但它解決了

1)這兩個問題當模態視圖被解除時調整大小

2)模式視圖無法在橫向模式下彈出

我希望這可以幫助別人在這個殘酷的蘋果世界。

-1

當你的主視圖回來,試着加入:

[myTableView setFrame:CGRectMake(0,0,320,411)];

+1

謝謝,但該解決方案有點過於靜態。根據我的經驗,調整到精確的尺寸往往會導致不必要的意外。我正在尋找一種解決方案,以防止首先出現轉移。 – story

0

如果你有意見相關的筆尖 - 進入筆尖爲每個視圖,並在每個筆尖主視圖設置以下屬性:

狀態欄:未指定

頂欄:不詳

底欄:未指定

在尺寸

然後: X:0,Y:0,W:320,H480

在分配每個視圖後回到代碼中,還在每個視圖上將'wantsFullScreenLayout'屬性設置爲TRUE。

編輯:(?也許:-))解釋

如果你有在筆尖指定一個狀態欄,則UIKit的自動調整你的意見,以應付狀態欄(你會看到你的查看yorigin爲0,筆尖高度爲460),但如果您在viewDidAppear方法中查看框架中的偏移/高度,則將其設置爲20/460以迎合狀態欄。

出於某種原因,呈現模態視圖控制器似乎與此混亂,並再次調整狀態欄,將視圖向下移動另一個20.將狀態欄設置爲未指定,並設置wantsFullScreen佈局停止uikit與您的框架混合,並讓您控制(因此在筆尖尺寸中將高度設置爲480)。

您還需要將所有視圖元素向下移動20以滿足480高度視圖中的狀態欄高度。

+0

對不起,如果我只是無知,但我不明白這將提供一個解決方案。 – story

+0

編輯我的答案,試圖解釋 – gamozzii

+0

謝謝你的嘗試,但這並沒有改變任何東西。它也像是掩蓋了一些更嚴重的潛在問題,這正是我想要處理的。 – story