我似乎无法弄清楚为什么我的应用程序在将对象添加到我的表时崩溃了。我使用这个 ( http://www.theappcodeblog.com/2011/05/09/parsing-xml-in-an-iphone-app-tutorial/) 教程来解析 XML,它确实很好,但没有将我解析的 XML 中的数据添加到 UITableView。
这是我使用的代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"starting table");
static NSString *cellid = @"Cell";
row *curname = [[xpar worker] objectAtIndex:indexPath.row];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellid];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellid]autorelease];
}
picframe = CGRectMake(0, 0, 100, 100);
UIImageView *imgview = [[UIImageView alloc]initWithFrame:picframe];
imgview.image = [UIImage imageNamed:[NSString stringWithFormat:@"%@", curname.pic]];
[cell.contentView addSubview:imgview];
nameframe = CGRectMake(105, 50, 50, 20);
namecon = [[UILabel alloc] initWithFrame:nameframe];
namecon.tag = 0011;
namecon.numberOfLines = 1;
namecon.font = [UIFont boldSystemFontOfSize:12.0];
[cell.contentView addSubview:namecon];
jobframe = CGRectMake(165, 75, 50, 20);
jobcon = [[UILabel alloc] initWithFrame:jobframe];
jobcon.tag = 0012;
jobcon.numberOfLines = 1;
jobcon.font = [UIFont systemFontOfSize:12.0];
[cell.contentView addSubview:jobcon];
majframe = CGRectMake(165, 25, 50, 20);
majcon = [[UILabel alloc] initWithFrame:majframe];
majcon.tag = 0013;
majcon.numberOfLines = 1;
majcon.font = [UIFont systemFontOfSize:12.0];
[cell.contentView addSubview:majcon];
namecon = (UILabel*)[cell.contentView viewWithTag:0011];
namecon.text = [curname name];
NSLog(@"%@", namecon.text);
jobcon = (UILabel*)[cell.contentView viewWithTag:0012];
jobcon.text = [curname job];
majcon = (UILabel*)[cell.contentView viewWithTag:0013];
majcon.text = [curname major];
return cell;
}
我在代码中使用带有 UITableView 和带有标识符“Cell”的 TableViewCell 的 Storyboard。 UIViewController的类是上面代码的.m文件,UITableView使用的是Dynamic Prototypes,UITableView的dataSource和Delegate Outlets是上面代码的.m文件,.m文件的Outlet链接到UITableView。
我也是 Objective-C 和 iOS 开发人员的新手,所以如果这是一个非常明显的答案,我很抱歉。我尝试了很多不同的事情都无济于事。如果我的代码中还有任何其他部分需要发布,我会尽快发布。
谢谢!
编辑: 崩溃后记录:
2014-04-07 13:18:17.383 LabWorker[80097:60b] -[workersViewController
tableView:heightForRowAtIndexPath:]: unrecognized selector sent to instance 0x10c3d4a60
2014-04-07 13:18:17.386 LabWorker[80097:60b] *** Terminating app due to uncaught exception
'NSInvalidArgumentException', reason: '-[workersViewController
tableView:heightForRowAtIndexPath:]: unrecognized selector sent to instance 0x10c3d4a60'
*** First throw call stack:
(
0 CoreFoundation 0x0000000101acd495 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x000000010182c99e objc_exception_throw + 43
2 CoreFoundation 0x0000000101b5e65d -[NSObject(NSObject)
doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x0000000101abeb85 ___forwarding___ + 453
4 CoreFoundation 0x0000000101abe938 _CF_forwarding_prep_0 + 120
5 UIKit 0x00000001005eba30 -[UISectionRowData
heightForRow:inSection:canGuess:] + 234
6 UIKit 0x00000001005f2334 -[UITableViewRowData
rectForRow:inSection:heightCanBeGuessed:] + 582
7 UIKit 0x00000001005f2432 -[UITableViewRowData
rectForGlobalRow:heightCanBeGuessed:] + 150
8 UIKit 0x00000001005f2dd5 -[UITableViewRowData
globalRowsInRect:canGuess:] + 359
9 UIKit 0x0000000100494531 -[UITableView
_visibleGlobalRowsInRect:] + 210
10 UIKit 0x00000001004937ab -[UITableView
_updateVisibleCellsNow:] + 881
11 UIKit 0x00000001004a5721 -[UITableView layoutSubviews] +
207
12 UIKit 0x0000000100439993 -[UIView(CALayerDelegate)
layoutSublayersOfLayer:] + 354
13 QuartzCore 0x000000010242a802 -[CALayer layoutSublayers] + 151
14 QuartzCore 0x000000010241f369
_ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 363
15 QuartzCore 0x000000010241f1ea
_ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24
16 QuartzCore 0x0000000102392fb8
_ZN2CA7Context18commit_transactionEPNS_11TransactionE + 252
17 QuartzCore 0x0000000102394030 _ZN2CA11Transaction6commitEv +
394
18 QuartzCore 0x000000010239469d
_ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 89
19 CoreFoundation 0x0000000101a98dc7
__CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
20 CoreFoundation 0x0000000101a98d37 __CFRunLoopDoObservers + 391
21 CoreFoundation 0x0000000101a78522 __CFRunLoopRun + 946
22 CoreFoundation 0x0000000101a77d83 CFRunLoopRunSpecific + 467
23 GraphicsServices 0x0000000102f79f04 GSEventRunModal + 161
24 UIKit 0x00000001003d9e33 UIApplicationMain + 1010
25 LabWorker 0x0000000100002fa7 main + 103
26 libdyld.dylib 0x00000001068985fd start + 1
27 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
编辑: 更多代码/解释:
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
NSLog(@"sections");
return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
NSLog(@"rows, %lu", (unsigned long)[[xpar worker] count]);
return [[xpar worker] count];
}
-(CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"CGFloat");
return 100;
}
它运行并获得 [[xpar worker] count] 的 11 行(正确的数字),然后运行“CGFloat”方法 11 次,然后它向我显示我上面发布的日志显示的内容。
编辑:崩溃的地方:
#import <UIKit/UIKit.h>
#import "labAppDelegate.h"
int main(int argc, char * argv[])
{
@autoreleasepool {
---> return UIApplicationMain(argc, argv, nil, NSStringFromClass([labAppDelegate class]));
}
}
它说它在 main.m 文件中它上面的箭头所在的位置崩溃。
参数 = 1
**argv = (char) '/'
最佳答案
你的日志说它需要 tableView:heightForRowAtIndexPath 方法
按照下面的方式实现这个方法
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return 100;
}
关于ios - 尝试从 NSMutableArray 填充 UITableView 时应用程序崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22907388/
我需要在客户计算机上运行Ruby应用程序。通常需要几天才能完成(复制大备份文件)。问题是如果启用sleep,它会中断应用程序。否则,计算机将持续运行数周,直到我下次访问为止。有什么方法可以防止执行期间休眠并让Windows在执行后休眠吗?欢迎任何疯狂的想法;-) 最佳答案 Here建议使用SetThreadExecutionStateWinAPI函数,使应用程序能够通知系统它正在使用中,从而防止系统在应用程序运行时进入休眠状态或关闭显示。像这样的东西:require'Win32API'ES_AWAYMODE_REQUIRED=0x0
对于具有离线功能的智能手机应用程序,我正在为Xml文件创建单向文本同步。我希望我的服务器将增量/差异(例如GNU差异补丁)发送到目标设备。这是计划:Time=0Server:hasversion_1ofXmlfile(~800kiB)Client:hasversion_1ofXmlfile(~800kiB)Time=1Server:hasversion_1andversion_2ofXmlfile(each~800kiB)computesdeltaoftheseversions(=patch)(~10kiB)sendspatchtoClient(~10kiBtransferred)Cl
我正在用Ruby编写一个简单的程序来检查域列表是否被占用。基本上它循环遍历列表,并使用以下函数进行检查。require'rubygems'require'whois'defcheck_domain(domain)c=Whois::Client.newc.query("google.com").available?end程序不断出错(即使我在google.com中进行硬编码),并打印以下消息。鉴于该程序非常简单,我已经没有什么想法了-有什么建议吗?/Library/Ruby/Gems/1.8/gems/whois-2.0.2/lib/whois/server/adapters/base.
我正在使用的第三方API的文档状态:"[O]urAPIonlyacceptspaddedBase64encodedstrings."什么是“填充的Base64编码字符串”以及如何在Ruby中生成它们。下面的代码是我第一次尝试创建转换为Base64的JSON格式数据。xa=Base64.encode64(a.to_json) 最佳答案 他们说的padding其实就是Base64本身的一部分。它是末尾的“=”和“==”。Base64将3个字节的数据包编码为4个编码字符。所以如果你的输入数据有长度n和n%3=1=>"=="末尾用于填充n%
Rackup通过Rack的默认处理程序成功运行任何Rack应用程序。例如:classRackAppdefcall(environment)['200',{'Content-Type'=>'text/html'},["Helloworld"]]endendrunRackApp.new但是当最后一行更改为使用Rack的内置CGI处理程序时,rackup给出“NoMethodErrorat/undefinedmethod`call'fornil:NilClass”:Rack::Handler::CGI.runRackApp.newRack的其他内置处理程序也提出了同样的反对意见。例如Rack
我想用ruby编写一个小的命令行实用程序并将其作为gem分发。我知道安装后,Guard、Sass和Thor等某些gem可以从命令行自行运行。为了让gem像二进制文件一样可用,我需要在我的gemspec中指定什么。 最佳答案 Gem::Specification.newdo|s|...s.executable='name_of_executable'...endhttp://docs.rubygems.org/read/chapter/20 关于ruby-在Ruby中编写命令行实用程序
为了将Cucumber用于命令行脚本,我按照提供的说明安装了arubagem。它在我的Gemfile中,我可以验证是否安装了正确的版本并且我已经包含了require'aruba/cucumber'在'features/env.rb'中为了确保它能正常工作,我写了以下场景:@announceScenario:Testingcucumber/arubaGivenablankslateThentheoutputfrom"ls-la"shouldcontain"drw"假设事情应该失败。它确实失败了,但失败的原因是错误的:@announceScenario:Testingcucumber/ar
我构建了两个需要相互通信和发送文件的Rails应用程序。例如,一个Rails应用程序会发送请求以查看其他应用程序数据库中的表。然后另一个应用程序将呈现该表的json并将其发回。我还希望一个应用程序将存储在其公共(public)目录中的文本文件发送到另一个应用程序的公共(public)目录。我从来没有做过这样的事情,所以我什至不知道从哪里开始。任何帮助,将不胜感激。谢谢! 最佳答案 无论Rails是什么,几乎所有Web应用程序都有您的要求,大多数现代Web应用程序都需要相互通信。但是有一个小小的理解需要你坚持下去,网站不应直接访问彼此
我尝试运行2.x应用程序。我使用rvm并为此应用程序设置其他版本的ruby:$rvmuseree-1.8.7-head我尝试运行服务器,然后出现很多错误:$script/serverNOTE:Gem.source_indexisdeprecated,useSpecification.Itwillberemovedonorafter2011-11-01.Gem.source_indexcalledfrom/Users/serg/rails_projects_terminal/work_proj/spohelp/config/../vendor/rails/railties/lib/r
刚入门rails,开始慢慢理解。有人可以解释或给我一些关于在application_controller中编码的好处或时间和原因的想法吗?有哪些用例。您如何为Rails应用程序使用应用程序Controller?我不想在那里放太多代码,因为据我了解,每个请求都会调用此Controller。这是真的? 最佳答案 ApplicationController实际上是您应用程序中的每个其他Controller都将从中继承的类(尽管这不是强制性的)。我同意不要用太多代码弄乱它并保持干净整洁的态度,尽管在某些情况下ApplicationContr