【问题标题】:Moving tableview on xcode 4.2在 xcode 4.2 上移动 tableview
【发布时间】:2013-03-01 14:30:42
【问题描述】:

我已经阅读了如何在 xcode4.2 上移动对象并且我确实成功地移动了一个按钮。但我不能移动 tableview。

这里是 Viewcontroller.m 上的代码:

- (IBAction) unhide {
if (flag==1) {
    flag=0;

    CGRect frame = testtable.frame;
    frame.origin.x = frame.origin.x; // new x coordinate
    frame.origin.y = 150; // new y coordinate



    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration: 0.25];
    testtable.frame = frame;
    [UIView commitAnimations];


}
else{
    flag=1;

    CGRect frame = testtable.frame;
    frame.origin.x = frame.origin.x; // new x coordinate
    frame.origin.y = 350; // new y coordinate



    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration: 0.25];
    testtable.frame = frame;
    [UIView commitAnimations];


}}

提前谢谢你。

【问题讨论】:

  • testtable 可能是nil。附言这个动画风格很老了,你应该使用iOS 4自带的新的基于块的风格
  • 究竟是什么不起作用?你的取消隐藏方法被调用了吗? testtable 实际上是 nil 吗?
  • @borrrden 我该如何解决?抱歉我的愚蠢问题,我完全是目标 c 的新手。如果你给我关于“基于块的”的教程,我很高兴。提前谢谢你。
  • @Shaun 是的,testtable 为零。当我单击取消隐藏按钮时,tableview 没有移动到新位置。
  • 有很多教程可用于新的基于块的方法。更重要的是确保testtable 确实有效(即不是nil

标签: ios objective-c xcode storyboard


【解决方案1】:

这很简单,不要忘记为表格视图创建出口。 例如,如果你的 outlet 名称是 testTable,那么试试这个代码块:

if(flag==0)
{
    flag=1;
    [UIView animateWithDuration:0.7 animations:^()
     {
         testTable.frame=CGRectMake(0, 150, testTable.frame.size.width, testTable.frame.size.height);
     }];
}
else
{
    flag=0;
    [UIView animateWithDuration:0.7 animations:^()
     {
         testTable.frame=CGRectMake(0, 350, testTable.frame.size.width, testTable.frame.size.height);
     }];
}

希望这会对您有所帮助。祝你好运

【讨论】:

  • 我做到了。非常感谢,祝你有美好的一天:D
猜你喜欢
  • 1970-01-01
  • 2012-01-09
  • 2019-06-24
  • 2013-02-12
  • 1970-01-01
  • 2012-03-02
  • 1970-01-01
  • 1970-01-01
  • 2014-01-06
相关资源
最近更新 更多