0

我有一个网格,当我单击我的正方形时,我的网格内部有 52 个正方形作为按钮,我应该转到另一个页面,但我的进程已终止,我不知道为什么?

你能帮帮我吗?

提前致谢!

听说是我的 YearView 页面(这里有 52 个正方形)

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
int rows = 13, columns = 4;
UIView *buttonView = [[UIView alloc] initWithFrame:CGRectMake(0.f, 0.f, 80*columns, 32*rows)];
int currentTag = 0;

for (int y = 0; y < rows; y++) {
    for (int x = 0; x < columns; x++) {

        UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom]; 
        //  [button.layer setBorderWidth:1.0]; 
        //  [button.layer setBorderColor:UIColor blackColor]];
        button.backgroundColor=[UIColor colorWithRed: 201.0/255.0 green: 201.0/255.0 blue:201.0/255.0 alpha: 1.0];
        button.tag = currentTag;
        currentTag++;
        [button.layer setBorderColor: [[UIColor blackColor] CGColor]];
        [button.layer setBorderWidth: 1.0];
        [button setTitle:[NSString stringWithFormat:@"%d",currentTag] forState:UIControlStateNormal];
        button.frame = CGRectMake(80*x, 32*y, 80, 32); 
        [button addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
        [buttonView addSubview: button];

    }
}

// Center the view which contains your buttons
CGPoint centerPoint = buttonView.center;
centerPoint.x = self.view.center.x;
buttonView.center = centerPoint;
[self.view addSubview:buttonView];    

}


-(void)buttonPressed:(UIButton *)button
{
NSLog(@"button %u -- frame: %@", button.tag, NSStringFromCGRect(button.frame));
WeekView *crtObj=[[WeekView alloc]initWithNibName:@"WeekView" bundle:nil];
[self.navigationController pushViewController:crtObj animated:YES];
// [crtObj release];


}

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString: @"WeekView"]){

        // Get reference to the destination view controller
     //  WeekView *vc = [segue destinationViewController];

        // Pass any objects to the view controller here, like...
       // [vc setMyObjectHere:object];
    [segue.destinationViewController setTitle:@"WeekView"];
    }}

编辑:

*首先抛出调用栈:

 (0x13e0022 0x1571cd6 0x1388a48 0x13889b9 0x24b638 0xf11fc 0xf1779 0xf199b 0xf1d11 0x1038fd 0x103aef 0x103dbb 
  0x10485f 0x104e06 0x104a24 0x3529 0x13e1e99 0x2d14e 0x2d0e6 0xd3ade 0xd3fa7 0xd3266 0x523c0 0x525e6 0x38dc4 
 0x2c634 0x12caef5 0x13b4195 0x1318ff2 0x13178da 0x1316d84 0x1316c9b 0x12c97d8 0x12c988a 0x2a626 0x204d 0x1fb5)
 terminate called throwing an exception(lldb) 


0xbffff5b4
0xbffff6d4

带调试 = Signal Sigabrat 从这里开始

WeekView *crtObj=[[WeekView alloc]initWithNibName:@"WeekView" bundle:nil];
4

1 回答 1

0

您正在使用情节提要,但您正在使用

WeekView *crtObj=[[WeekView alloc]initWithNibName:@"WeekView" bundle:nil];
[self.navigationController pushViewController:crtObj animated:YES];

我想你想在这里使用故事板:

[self performSegueWithIdentifier:@"WeekView" sender:self];
于 2012-06-21T12:36:04.283 回答