我有一个网格,在我的网格内部有52个方格作为按钮当我点击我的方块时我应该去另一个页面但是我的进程被终止我不知道为什么?
你能帮我吗?提前致谢!
听到的是我的年度视图页面(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
with debugging = Signal Sigabrat从这里开始
WeekView *crtObj=[[WeekView alloc]initWithNibName:@"WeekView" bundle:nil];
答案 0 :(得分:0)
您正在使用故事板,但您正在使用
WeekView *crtObj=[[WeekView alloc]initWithNibName:@"WeekView" bundle:nil];
[self.navigationController pushViewController:crtObj animated:YES];
我想你想在这里使用故事板:
[self performSegueWithIdentifier:@"WeekView" sender:self];