1

我创建了一个 UIViewController,上面有一个按钮。该按钮的唯一工作是创建一个用于绘制一些矩形的窗口。(我从 Apple 的示例应用程序的“QuartzDemo”中获取了一些代码。)Objective C 真的很适合我……

当我尝试这个时,没有任何反应。

这是按钮的代码:

- (IBAction)startButtonAct:(id)sender
{
    QuartzViewController *controller;

    NSLog(@"1");
    controller = [[QuartzViewController alloc] initWithTitle:@"Dotsie"];
    controller.quartzViewDelegate = [[[RectDrawing alloc] init] autorelease];
    [[self navigationController] pushViewController:controller animated:YES];
    // [controller release];

}

老实说,我不确定其他人还需要看什么,但这里有一些其他的东西:

@interface QuartzViewController : UIViewController
{
    QuartzView *quartzView;
    UIBarStyle barStyle;
    UIStatusBarStyle statusStyle;

}


@protocol QuartzViewDelegate;

@interface QuartzView : UIView {

id<QuartzViewDelegate> delegate;

}

@property(assign) id<QuartzViewDelegate> delegate;

@end

@protocol QuartzViewDelegate<NSObject>

@required

// Draw contents into the given view, using the given context and bounds.
-(void)drawView:(QuartzView*)view inContext:(CGContextRef)context bounds:(CGRect)bounds;

@end

请帮忙——这让我发疯了——我已经与同样的基本问题作斗争了一个星期......

4

1 回答 1

1

首先,应该有 [controller release] 行,没有注释。我确定您只是将其禁用以进行调试。

如果插入该行:

NSLog(@"%@", [self navigationController]);

在您的按钮操作中,它是记录一个有效的控制器还是说为零?如果它为零,我的猜测是这个视图控制器没有正确地推送到导航控制器本身。

于 2009-06-13T23:31:14.827 回答