我有以下工作片段:
for (UIButton *b in buttonMapping) {
[b setTitle:@"yo!" forState:UIControlStateNormal];
[NSThread sleepForTimeInterval:1.0];
}
Run Code Online (Sandbox Code Playgroud)
有四个按钮,所有四个按钮都会更新.但是,不是每秒更新一次,而是四秒钟,它们都会更新.
如何强制UIButton更新?或者这不是推荐的睡眠方法吗?
我发现自己在C++中编写了一些重复的代码.我正在使用一些自动生成的,这样如果我想处理Foo,Bar和Baz,它们都有相当类似的方法.例如,get_foo,get_bar,get_baz等.
对于每一件"事物",我或多或少都要做同样的事情.检查它是否存在,是否存在,获取日志,查找日志中的最新条目,检查条目是否存在等等.
这导致了相当多的重复代码,类似于:
if (obj->has_foo) {
if(obj->get_foo().has_log()) {
Log *l = obj->get_foo().get_foo_log();
if (!l) {
ERROR("Foo does not have a log")
}
... 30-40 more lines of stuff ...
}
}
if (obj->has_bar) {
if(obj->get_bar().has_log()) {
Log *l = obj->get_bar().get_bar_log();
if (!l) {
ERROR("Bar does not have a log")
}
... 30-40 more lines of stuff ...
}
}
if (obj->has_baz) {
if(obj->get_baz().has_log()) {
Log *l = obj->get_baz().get_baz_log();
if (!l) {
ERROR("Baz does not have a log")
}
... 30-40 …Run Code Online (Sandbox Code Playgroud) 我有一个方法绑定到四个按钮.我想创建一个包含每个按钮的数组,然后检索并与数组中的按钮进行交互.我在下面修补的代码.当我尝试从阵列中获取一个按钮并向其发送消息时,它会变成kablooie.
对我做错了什么的想法?
Hack_DumpViewController.h
#import <UIKit/UIKit.h>
@interface Hack_DumpViewController : UIViewController {
IBOutlet UIButton *redButton;
IBOutlet UIButton *greenButton;
IBOutlet UIButton *blueButton;
IBOutlet UIButton *yellowButton;
NSArray *buttonMapping;
}
- (IBAction) changeToYo:(id)sender;
@property (nonatomic, retain) UIButton *redButton;
@property (nonatomic, retain) UIButton *greenButton;
@property (nonatomic, retain) UIButton *blueButton;
@property (nonatomic, retain) UIButton *yellowButton;
@property (nonatomic, retain) NSArray *buttonMapping;
@end
Run Code Online (Sandbox Code Playgroud)
Hack_DumpViewController.m
#import "Hack_DumpViewController.h"
@implementation Hack_DumpViewController
@synthesize redButton;
@synthesize greenButton;
@synthesize yellowButton;
@synthesize blueButton;
@synthesize buttonMapping;
- (IBAction) changeToYo:(id)sender {
NSLog(@"changing numbers!");
for (UIButton *b in buttonMapping) …Run Code Online (Sandbox Code Playgroud) 我正在学习Cocoa/Objective-C/iPhone SDK,作为一个应用我学到的东西的简单项目,我想创建一个简单版本的Simon游戏.四个彩色按钮,你会看到一个序列(红色,绿色,蓝色,红色等),你必须重复序列.
我相信我已经找到了大部分内容,除了一件:向用户显示序列.具体来说,如何实现突出显示按钮并在200ms后将其恢复正常之间的延迟.
如果我在主运行循环中睡眠,则更新不会正确发生(即使我明确调用setNeedsDisplay).如果我产生一个新线程,事情会很快变得复杂,因为我的类方法需要返回UI元素(即时变量).
有什么建议?
我试过搜索CPAN.我发现Mac::iTunes,但不是一种为特定曲目分配评级的方法.
我正在阅读"开始iPhone开发"一书并在第9章中停留.我花了几个小时试图调试此错误而无济于事:
2010-05-01 19:27:51.361 Nav2[4113:20b] *** Assertion failure in -[UITableView _createPreparedCellForGlobalRow:withIndexPath:], /SourceCache/UIKit/UIKit-984.38/UITableView.m:4709
2010-05-01 19:27:51.362 Nav2[4113:20b] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath:'
2010-05-01 19:27:51.364 Nav2[4113:20b] Stack: (
...
)
Run Code Online (Sandbox Code Playgroud)
我不是在寻求这本书的帮助,而是关于如何调试此错误的提示.我能确定哪种cellForRowAtIndexPath方法是问题吗?以及如何检查类型?或者我应该看看其他什么?
编辑:根据要求,两个可疑方法的代码:
-(UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *RootViewControllerCell = @"RootViewControllerCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:RootViewControllerCell];
if (cell == nil) {
cell == [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:RootViewControllerCell] autorelease];
}
NSUInteger row = [indexPath row];
SecondLevelViewController …Run Code Online (Sandbox Code Playgroud) 我有一个代表Flickr照片的NSDictionary.
照片的描述看起来像这样:
{
accuracy = 16;
context = 0;
dateupload = 1355106635;
description = {
"_content" = "Barclays Center Arena\nAtlantic Yards\nProspect Heights\nBrooklyn, New York";
};
farm = 9;
"geo_is_contact" = 0;
"geo_is_family" = 0;
"geo_is_friend" = 0;
"geo_is_public" = 1;
id = 8260097924;
isfamily = 0;
isfriend = 0;
ispublic = 1;
latitude = "40.681786";
longitude = "-73.972545";
originalformat = jpg;
originalsecret = cd1bdd846a;
owner = "62968578@N07";
ownername = atlanticyardswebcam02;
"place_id" = "uUNC_q9TWr1vROR4wA";
secret = 320e308baa;
server = 8502;
tags …Run Code Online (Sandbox Code Playgroud)