Tag: 笔尖

为什么加载一个nib时这个init方法返回一个超出范围的对象?

为什么这个init方法返回一个超出范围的对象? 使用XCode 4.2,4.3的基础SDK和ARC,我试图从一个笔尖(而不是一个UIViewController)加载一个UIView。 我不需要在这个过程中使用UIViewController。 看到这个答案后,看起来可以这样做: 如何使用用Interface Builder创build的nib文件加载UIView (用户“MusiGenesis”的答案描述了这个过程) 我用一个标签创build了一个UIView的子类: @interface MyView : UIView @property (unsafe_unretained, nonatomic) IBOutlet UILabel *textLabel; @end 在实现中,我重写了initWithFrame: – (id)initWithFrame:(CGRect)frame { //self = [super initWithFrame:frame]; self = [JVUIKitUtils initWithNibName:@"MyView" withOwner:self]; if( self ) { NSLog(@"Created"); } return self; } 在IB中,我用一个视图创build了一个名为“MyView.xib”的文件。 它有一个标签作为子视图,并通过将其拖到h文件来创build标签属性。 而在另一个文件中,我创build了这个可重用的静态方法: + (id)initWithNibName:(NSString*)nibName withOwner:(id)uiView { id object = nil; NSArray *bundle […]

UIViewController initWithNibName结果为零视图

我试图做一个视图控制器,将始终加载相同的笔尖。 我的初始化代码如下所示: -(id)init { NSString* nibName; if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) nibName = @"XIB_iPad"; else nibName = @"XIB_iPhone"; self = [super initWithNibName:nibName bundle:nil]; if (self) { … } return self; } – (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { return [self init]; } 问题是这个代码导致视图控制器没有视图。 有什么我在这里做错了吗? 有一个更好的方法吗? 谢谢。

使用NIB定义从故事板出来的UITableViewCell

我使用Json数组来显示来自服务器的数据。 当我将CellIdentifier更改为我在CellIdentifier中使用的@Cell时,pushDetailView正在工作,它将进入下一页,但是当我再次更改为CustomCell时,只需在第一页中显示城市和州的名称,而当我点击时不会去下一页。 我需要@CustomCell的原因是因为在第一页需要2个标签视图,当我将其更改为@cell时,它只显示一个标签。 谢谢。 – (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"CustomCell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (!cell) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier]; } // Configure the cell… City * cityObject; cityObject = [ citiesArry objectAtIndex:indexPath.row]; cell.textLabel.text = cityObject.cityState; cell.detailTextLabel.text = cityObject.cityPopulation; cell.detailTextLabel.numberOfLines = 4; //NSData *imageData = […]

在运行时从静态UITableView中删除行

是否有可能在运行时从UITableView中删除行,当所有的部分和行是在一个笔尖静态定义? 在下面的故事板场景中,我可以在运行时删除“Addr 2”字段吗? 在这种情况下,我没有提供数据源到UITableView 。

iOS – 无需使用笔尖即可支持iPad和iPhone

我试图编写一个应用程序,而不使用笔尖 ,我会以编程方式做的一切。 现在的问题是,我将如何支持iPad和iPhone ? 显然,我不能这样做 if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) { // load iPad nib } else { // load iPhone nib } 如果我创build2 ViewControllers ,那么IBAction将是多余的。 任何build议?

点击共享button时,QLPreviewController崩溃,内部一致性笔尖包错误

我正在呈现一个QLPreviewController模态。 一切正常 – popup,显示预览项目和一切。 但是,一旦分享button被轻敲,应用程序崩溃在设备上,并在模拟器中: 2013-05-03 20:10:53.563 appname[16860:c07] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle <{{app_path}}> (loaded)' with name '_UIDocumentActivityViewController'' 这是相关的代码: #pragma mark HVSchedulesDelegate – (void)schedulePDFReceived { QLPreviewController *previewController = [[QLPreviewController alloc] init]; [previewController setDataSource:self]; [self presentViewController:previewController animated:YES completion:nil]; } #pragma mark QLPreviewControllerDataSource – (NSInteger) numberOfPreviewItemsInPreviewController:(QLPreviewController […]

我的自定义UIView dos不接收触摸

使用IB,我创build了一个包含几个button的小型子视图。 我的控制器从xib文件读取小视图,并将其作为子视图添加到主视图。 它加载好,我可以看到子视图和所有的button。 据我所知,它也连接到控制器中的IBOutlets和IBActions。 但是,当我按下button什么都没有发生! 事实上,当我按下button超级视图的touchesBegan被调用! 超级视图也包含一个“普通button”(即我的子视图的兄弟),该button工作正常! 问题:为什么我的子视图上的button不起作用? -(void) loadMultibutt{ self.buttErase = nil; // test if the outlet connects NSArray *arr = [[NSBundle mainBundle] loadNibNamed:@"multibutt_ipad" owner:self options:nil]; UIView *viewButts = [arr objectAtIndex:0]; ViewWorkbench* vw = (ViewWorkbench*) self.view; [vw addMultibuttView:viewButts]; // now, buttErase != nil. NSSet *setTest = [self.buttErase allTargets]; NSLog(@"setTest = %@", setTest); // This […]

UITableView从NIB文件加载一个自定义单元格抛出NSInternalInconsistencyException

在一个iOS应用程序中,我有一个UITableView。 在cellForRowAtIndexPath方法中,我需要使用它的NIB名称返回一个自定义单元格。 为此我使用loadNibNamed 。 (我将在“willDisplayCellforRowAtIndexPath”中加载后填充单元格中的数据) MyItemCell是包含2个UIImageView和一个UIButton的XIB文件(MyItemCell.xib)(每个项目都有一个标签) 这是我的代码: 在我的viewController – (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { return [ViewHelper loadCustomCellWithNibName:@"MyItemCell" owner:self]; } 并从NIB加载自定义单元格的方法 + (UITableViewCell *) loadCustomCellFromNib:(NSString *)nibName owner:(id)owner { UITableViewCell *cell = nil; NSArray *nibObjects = [[NSBundle mainBundle] loadNibNamed:nibName owner:owner options:nil]; if([nibObjects count] > 0 ) { cell = [nibObjects objectAtIndex:0]; } else { NSLog(@"Failed to […]

AutoLayout的问题与在NIB文件中定义并在StoryBoard中使用的自定义视图

我已经在NIB文件中定义了一个自定义的视图,并且想在一个StoryBoard中实例化一个副本,但是我遇到了有关自动布局的问题。 在一个简单的例子中,自定义视图具有固定大小的单个标签并且垂直和水平居中,全部使用自动布局。 文件所有者被设置为我的class级,它有一个出口到顶视图。 在自定义视图实现中,我执行: – (id)initWithCoder:(NSCoder *)aDecoder { self = [super initWithCoder:aDecoder]; if(self) { [[NSBundle mainBundle] loadNibNamed:@"FMCompassView" owner:self options:nil]; [self addSubview:self.topView]; } return self; } 现在,在我的故事板中,我添加了一个UIView,将它的类设置为我的自定义类,然后再使用自动布局将其设置为在页面上的大小和居中。 而我的小工具的位置和大小正确,但它的内容不resize,如下所示: 从NIB加载之后,我尝试添加更多的约束条件,如下所示: UIView* subV = self.topView; NSDictionary *viewsDictionary = NSDictionaryOfVariableBindings(subV); [self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"|[subV]|" options:NSLayoutFormatAlignAllBaseline metrics:nil views:viewsDictionary]]; [self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[subV]|" options:NSLayoutFormatAlignAllBaseline metrics:nil views:viewsDictionary]]; 但是这会导致无效的布局限制。 任何想法如何得到这个工作? 干杯!

如何执行从故事板的笔尖继续

我有90%的当前项目在故事板完成,但我也使用一个单一的xib视图控制器的“input您的pin”视图,因为这是它被集成到我导入到我的项目github项目的方式。 我需要从xib回到故事板。 从故事板到xib的操作很简单,但是现在我想在故事板中使用另一个视图。 有什么build议么? 首先,我试图将xib转换为故事板中的视图,但由于它是为了与笔尖配合而devise的,因此我失败了。