MoreFunctionViewController.h 代码如下:
#import <UIKit/UIKit.h>
@interface MoreFunctionViewController : UIViewController <UITableViewDelegate,UITableViewDataSource>{
UITableView *moreTable;
}
@property (nonatomic, retain) UITableView *moreTable;
@end
和 MoreFunctionViewController.m 代码如下:
#import "MoreFunctionViewController.h"
#import "CustomNavigationBar.h"
#import "MyShakeViewController.h"
@implementation MoreFunctionViewController
@synthesize moreTable;
- (void)viewDidLoad {
[super viewDidLoad];
self.title = @"More";
CGRect tableFrame = self.view.frame;
tableFrame.origin.y -= 20;
moreTable = [[UITableView alloc] initWithFrame:tableFrame style:UITableViewStyleGrouped];
moreTable.delegate = self;
moreTable.dataSource = self;
moreTable.backgroundColor = [UIColor clearColor];
[self.view addSubview:moreTable];
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self.navigationController.navigationBar setBackgroundImage:nil];
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"twoNavbar.png"]];
}
..................
..................
- (void)tableView: (UITableView *)tableView didSelectRowAtIndexPath: (NSIndexPath *)indexPath
{
if (indexPath.section == 0) {
if (indexPath.row == 0) {
NSLog(@"ddd");
MyShakeViewController *myshakeView = [[MyShakeViewController alloc] init];
[self.navigationController pushViewController:myshakeView animated:YES];
[myshakeView release];
}
}
}
MyShakeViewController -(void) viewDidLoad 方法如下:
-(void) viewDidLoad{
self.title = @"TestTitle";
}
但是看不到标题。 如果我改变
[self.navigationController pushViewController:myshakeView animated:YES];
到
[self.navigationController pushViewController:myshakeView animated:NO];
我可以看到 title ,这是为什么?
但我需要动画 YES
我该怎么做!
最佳答案
尝试在 MoreFunctionViewController 中设置标题:
MyShakeViewController *myshakeView = [[MyShakeViewController alloc] init];
myShakeView.title = @"TestTitle";
[self.navigationController pushViewController:myshakeView animated:YES];
[myshakeView release];
至于为什么,我不确定,我只使用 initWithNibName 创建了 View Controller (因此标题是从 Nib 加载的)和/或在导航项中使用自定义标题 View (因此我将标题 View 替换为我自己的 View ),因此我没有使用您的特定设置。
关于objective-c - 关于 self.navigationController pushViewController (IOS),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7657353/
类classAprivatedeffooputs:fooendpublicdefbarputs:barendprivatedefzimputs:zimendprotecteddefdibputs:dibendendA的实例a=A.new测试a.foorescueputs:faila.barrescueputs:faila.zimrescueputs:faila.dibrescueputs:faila.gazrescueputs:fail测试输出failbarfailfailfail.发送测试[:foo,:bar,:zim,:dib,:gaz].each{|m|a.send(m)resc
我已经从我的命令行中获得了一切,所以我可以运行rubymyfile并且它可以正常工作。但是当我尝试从sublime中运行它时,我得到了undefinedmethod`require_relative'formain:Object有人知道我的sublime设置中缺少什么吗?我正在使用OSX并安装了rvm。 最佳答案 或者,您可以只使用“require”,它应该可以正常工作。我认为“require_relative”仅适用于ruby1.9+ 关于ruby-主要:Objectwhenrun
如果您尝试在Ruby中的nil对象上调用方法,则会出现NoMethodError异常并显示消息:"undefinedmethod‘...’fornil:NilClass"然而,有一个tryRails中的方法,如果它被发送到一个nil对象,它只返回nil:require'rubygems'require'active_support/all'nil.try(:nonexisting_method)#noNoMethodErrorexceptionanymore那么try如何在内部工作以防止该异常? 最佳答案 像Ruby中的所有其他对象
我正在尝试为我的iOS应用程序设置cocoapods但是当我执行命令时:sudogemupdate--system我收到错误消息:当前已安装最新版本。中止。当我进入cocoapods的下一步时:sudogeminstallcocoapods我在MacOS10.8.5上遇到错误:ERROR:Errorinstallingcocoapods:cocoapods-trunkrequiresRubyversion>=2.0.0.我在MacOS10.9.4上尝试了同样的操作,但出现错误:ERROR:Couldnotfindavalidgem'cocoapods'(>=0),hereiswhy:U
#app/models/product.rbclassProduct我从Controller调用方法1。当我运行程序时。我收到一个错误:method_missing(atlinemethod2(param2)).rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activerecord-5.0.0/lib/active_record/relation/batches.rb:59:in`block(2levels)infind_each... 最佳答案 classProduct说明:第一个是类
我明白了defa(&block)block.call(self)end和defa()yieldselfend导致相同的结果,如果我假设有这样一个blocka{}。我的问题是-因为我偶然发现了一些这样的代码,它是否有任何区别或者是否有任何优势(如果我不使用变量/引用block):defa(&block)yieldselfend这是一个我不理解&block用法的具体案例:defrule(code,name,&block)@rules=[]if@rules.nil?@rules 最佳答案 我能想到的唯一优点就是自省(introspecti
我正在尝试获得良好的Ruby编码风格。为防止意外调用具有相同名称的局部变量,我总是在适当的地方使用self.。但是现在我偶然发现了这个:classMyClass上面的代码导致错误privatemethodsanitize_namecalled但是当删除self.并仅使用sanitize_name时,它会起作用。这是为什么? 最佳答案 发生这种情况是因为无法使用显式接收器调用私有(private)方法,并且说self.sanitize_name是显式指定应该接收sanitize_name的对象(self),而不是依赖于隐式接收器(也是
在Ruby(尤其是Rails)中,您经常需要检查某物是否存在,然后对其执行操作,例如:if@objects.any?puts"Wehavetheseobjects:"@objects.each{|o|puts"hello:#{o}"end这是最短的,一切都很好,但是如果你有@objects.some_association.something.hit_database.process而不是@objects呢?我将不得不在if表达式中重复两次,如果我不知道实现细节并且方法调用很昂贵怎么办?显而易见的选择是创建一个变量,然后测试它,然后处理它,但是你必须想出一个变量名(呃),它也会在内存中
我在我的rails应用程序中安装了来自github.com的acts_as_versioned插件,但有一段代码我不完全理解,我希望有人能帮我解决这个问题class_eval我知道block内的方法(或任何它是什么)被定义为类内的实例方法,但我在插件的任何地方都找不到定义为常量的CLASS_METHODS,而且我也不确定是什么here,并且有问题的代码从lib/acts_as_versioned.rb的第199行开始。如果有人愿意告诉我这里的内幕,我将不胜感激。谢谢-C 最佳答案 这是一个异端。http://en.wikipedia
如thisanswer中所述,Array.new(size,object)创建一个数组,其中size引用相同的object。hash=Hash.newa=Array.new(2,hash)a[0]['cat']='feline'a#=>[{"cat"=>"feline"},{"cat"=>"feline"}]a[1]['cat']='Felix'a#=>[{"cat"=>"Felix"},{"cat"=>"Felix"}]为什么Ruby会这样做,而不是对object进行dup或clone? 最佳答案 因为那是thedocumenta