小编sar*_*unw的帖子

实例变量:self vs @

这是一些代码:

class Person
  def initialize(age)
    @age = age
  end

  def age
    @age
  end

  def age_difference_with(other_person)
    (self.age - other_person.age).abs
  end

  protected :age
end
Run Code Online (Sandbox Code Playgroud)

我想知道的是两者的区别@age,并self.ageage_difference_with方法.

ruby instance-variables self

175
推荐指数
4
解决办法
4万
查看次数

我应该使用Core Data中的NSNumber(整数16,32,64)来保留NSUInteger

我想将NSUInteger保留到我的核心数据中,我不知道应该使用哪种类型(整数16,32,64)来满足所需的空间.

根据我的理解:

Integer 16 can have minimum value of -32,768 to 32,767
Integer 32 can have minimum value of -2,147,483,648 to 2,147,483,647
Integer 64 can have minimum value of -very large to very large
Run Code Online (Sandbox Code Playgroud)

和NSUInteger是unsigned long的类型def,等于unsigned int(iPhone上的objective-c中的类型)

所以,如果我使用numberWithUnsignedInteger将我的NSUInteger转换为NSNumber:并将其保存为NSNumber(整数32),我可以安全地检索我的数据吗?

core-data nsuinteger

66
推荐指数
2
解决办法
4万
查看次数

在轨道中#TODO

我读过一本rails书,一旦发现我们可以在代码中添加#TODO:和一些#stuff,所以我们可以通过一些rake cmd来回顾一下.

我的问题是我无法找到那些"#stuff"和"rake cmd"我在哪里google并搜索,但找不到并且不知道要搜索哪些关键字.

谢谢,

ruby ruby-on-rails

40
推荐指数
4
解决办法
1万
查看次数

是否存在NSDouble,NSFloat或NSInteger以外的其他类型?

In Cocoa,您更喜欢NSInteger还是普通的int,为什么?,有提及NSDoubleNSFloat,但我看不到任何文件中的参考.如果NSInteger建筑安全的目的是什么,那么其他类型如:doublefloat

cocoa types objective-c

36
推荐指数
2
解决办法
3万
查看次数

如何导航到同一个父状态

根据我从Gmail和TED应用程序观察到的向上导航的行为,它将导航到具有相同状态(滚动位置)的父级,而不像谷歌在他们的文档中所说的实施向上导航,就像创建父意图并启动它一样.

我实现了Android示例代码中的代码,所有状态都消失了(我之前设置的所有额外参数和滚动位置).这是什么方法?我在Android文档上找不到任何内容.

以下是代码:

public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
    case android.R.id.home:
        Intent upIntent = new Intent(this, MyParentActivity.class);
        if (NavUtils.shouldUpRecreateTask(this, upIntent)) {
            // This activity is not part of the application's task, so create a new task
            // with a synthesized back stack.
            TaskStackBuilder.from(this)
                    .addNextIntent(new Intent(this, MyGreatGrandParentActivity.class))
                    .addNextIntent(new Intent(this, MyGrandParentActivity.class))
                    .addNextIntent(upIntent)
                    .startActivities();
            finish();
        } else {
            // This activity is part of the application's task, so simply
            // navigate up to the hierarchical parent activity.
            NavUtils.navigateUpTo(this, upIntent); …
Run Code Online (Sandbox Code Playgroud)

android android-intent android-actionbar

36
推荐指数
2
解决办法
1万
查看次数

bundle id是否需要区分大小写?

在配置文件中,我将我的应用程序ID设置为com.mycompany.lowercaseappname,但在Xcode 4中,捆绑包标识符自动配置为使用my ${PRODUCT_NAME},大写(我希望用户在应用程序图标下看到它大写).这是正常的还是我需要在Xcode中手动更改包ID以小写?

xcode app-store cfbundleidentifier ios xcode4

24
推荐指数
2
解决办法
1万
查看次数

在objective-c中@property和@synthesize

当我在https://github.com/enormego/EGOTableViewPullRefresh玩游戏并弄清楚它是如何工作的时候,我发现了@property和@synthesize的神秘感.这是我提到的代码

EGORefreshTableHeaderView.h

@interface EGORefreshTableHeaderView : UIView {
    id _delegate;
    EGOPullRefreshState _state;

    UILabel *_lastUpdatedLabel;
    UILabel *_statusLabel;
    CALayer *_arrowImage;
    UIActivityIndicatorView *_activityView;
}

@property(nonatomic,assign) id <EGORefreshTableHeaderDelegate> delegate;
Run Code Online (Sandbox Code Playgroud)

EGORefreshTableHeaderView.m

@synthesize delegate=_delegate;
Run Code Online (Sandbox Code Playgroud)

我已经阅读了这个http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/ObjectiveC/Chapters/ocProperties.html,据我所知,它为_delegate创建了一个新的名称,即委托.(这是我的理解吗?)

但我仍然不明白为什么他们必须使那些@synthesize =指令复杂化.

synthesis properties objective-c

18
推荐指数
2
解决办法
6万
查看次数

重新排序时无法将UITableViewCell从其当前位置拖动

我正在尝试使我的核心数据支持UITableView具有重新排序能力,在实现所有这些委托和一些技术为这里提到的核心数据后,我发现了奇怪的行为.点击编辑按钮后,重新排序图标显示就好了,我可以点击它,阴影显示,但当我尝试将其移动到其他行时,我突然失去焦点,细胞移回到它的位置.有谁知道这个问题的原因?

这是显示问题的视频

http://www.youtube.com/watch?v=ugxuLNL7BnU&feature=youtu.be

这是我的代码

- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
{
    return YES;
}
Run Code Online (Sandbox Code Playgroud)

-tableView:moveRowAtIndexPath:toIndexPath我尝试下面的代码,只是一个空的实现,但问题仍然存在,所以我不认为这不是一个问题.

- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath
{
    _changeIsUserDriven = YES;

    NSUInteger fromIndex = sourceIndexPath.row;
    NSUInteger toIndex = destinationIndexPath.row;

    NSMutableArray *newsArray = [[self.fetchedResultsController fetchedObjects] mutableCopy];
    News *news = [self.fetchedResultsController.fetchedObjects objectAtIndex:fromIndex];

    [newsArray removeObject:news];
    [newsArray insertObject:news atIndex:toIndex];

    int i = 1;
    for (News *n in newsArray) {
        n.displayOrder = [NSNumber numberWithInt:i++];
    }

    [self saveContext];

    _changeIsUserDriven = NO;
}
Run Code Online (Sandbox Code Playgroud)

FetchedResultController委托

    - (void)controllerWillChangeContent:(NSFetchedResultsController *)controller …
Run Code Online (Sandbox Code Playgroud)

uitableview ios

16
推荐指数
1
解决办法
2922
查看次数

Ruby中的"和","或"运算符背后有智慧吗?

我不知道为什么红宝石给and,or少优先级比&&,||和赋值运算符?有什么缘故吗?

ruby operators logical-operators

10
推荐指数
3
解决办法
1204
查看次数

如何在没有UITableView的情况下实现UITableViewCell

我想使用UITableViewCell的功能,如披露附件,但我不需要整个UITableView.这样做是否可行且适当?我没有在UITableViewCell上看到任何委托,所以不知道我在哪里将代码放在- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath;任何参考或建议中?

uitableview ios

9
推荐指数
1
解决办法
3226
查看次数