Jam*_*nay 1 iphone xcode objective-c
所以继续我的挂断,我创建一个数组,将按钮传递到它并使用for循环试图将每个按钮放在视图上.我知道他们将处于相同的位置,因为他们都经历了相同的CGRectMake.但是我似乎无法在屏幕上放置任何代码,尽管它没有返回任何错误,但仍然让我难以理解为什么.
有人有什么建议吗?谢谢!
- (void)practiceMethod{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Practice Method has begun" message:@"Alert" delegate: self cancelButtonTitle:@"Close" otherButtonTitles: nil];
//[alert show];
[alert release];
float i=0;
CGRect applicationFrame = [[UIScreen mainScreen] applicationFrame];
UIImage *buttonGraphic = [UIImage imageNamed:@"1.png"];
UIButton *buttonOne = [[UIButton alloc] initWithFrame:applicationFrame];
UIButton *buttonTwo = [[UIButton alloc] initWithFrame:applicationFrame];
buttonArray = [[NSArray alloc] initWithObjects:buttonOne, buttonTwo,nil];
for (i = 0; i > [buttonArray count]; i++) {
UIButton *tempElement = [buttonArray objectAtIndex:i];
tempElement.frame = CGRectMake(140, 230, 50, 50);
[tempElement setBackgroundImage:buttonGraphic forState:UIControlStateNormal];
[self addSubview:tempElement];
}
}
Run Code Online (Sandbox Code Playgroud)
更改
for (i = 0; i > [buttonArray count]; i++) {
至
for (i = 0; i < [buttonArray count]; i++) {
你会起来跑步的.
PS.我建议您使用Objective-Cs for each迭代器来解决这些问题:
for( UIButton* button in buttonArray )
{
// stuff with button
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3542 次 |
| 最近记录: |