2013-05-06 44 views
0

我一直在爲此苦苦掙扎,並希望任何人都可以闡明爲什麼這不起作用。向TableViewCell添加Popover

我只是試圖在TableViewCell上實現一個Popover。這裏是代碼..

TodoView.m

- (void)tableView:(TUITableView *)tableView didClickRowAtIndexPath:(TUIFastIndexPath *)indexPath withEvent:(NSEvent *)event { 

    // MyViewController is a TUIViewController with a nib called MyView with just a button in it 
    MyViewController *t = [[MyViewController alloc] initWithNibName:@"MyView" bundle:nil]; 
    TUIView *theView = [[TUIView alloc] initWithFrame:NSMakeRect(0, 0, 300, 300)]; 

    TUIPopover *myPopover = [[TUIPopover alloc] initWithContentViewController:t]; 
    [myPopover showRelativeToRect:NSMakeRect(0, 0, 300, 300) ofView:theView preferredEdge:NSMaxYEdge]; 
} 

有一段時間,什麼都不會顯示出來。我可以告訴一些事情正在發生,因爲窗口本身會失去焦點,就好像一個Popover 在那裏是

有時我會看到一個非常小的blip-像2px×2px的小矩形。很難看到它,看起來像屏幕上的壞點,但有時候我會運行這段代碼。

TUIPopover來自Twitter UIKit Framework

一些可能性...

1)酥料餅不能被看到在CGFillRect?

TodoTableViewCell.m

- (void)drawRect:(CGRect)rect 
{ 
    CGRect b = self.bounds; 
    CGContextRef ctx = TUIGraphicsGetCurrentContext(); 

    CGContextSetRGBFillColor(ctx, 247.0/255, 247.0/255, 247.0/255, 1); 
    CGContextFillRect(ctx, b); 
} 

2)酥料餅不適合TableViewCell內,不能被看作

任何人有什麼想法?

回答

1

真正簡單的答案:

我忘了設定的酥料餅的內容大小!

因此,對於任何想知道爲什麼他們的彈出不起作用的人,請確保設置了內容大小!

TUIPopover *p = [[TUIPopover alloc] initWithContentViewController:commentsViewController]; 
[p setAnimates:TRUE]; 
[p setContentSize:CGSizeMake(300, 350)]; 
[p setBehaviour:TUIPopoverViewControllerBehaviourTransient]; 
[p showRelativeToRect:b.bounds ofView:b preferredEdge:CGRectMinYEdge];