小编Jon*_*Jon的帖子

如何使用NSNotificationCenter传递对象

我试图将我的app委托中的对象传递给另一个类中的通知接收器.

我想传递整数messageTotal.现在我有:

在接收器中:

- (void) receiveTestNotification:(NSNotification *) notification
{
    if ([[notification name] isEqualToString:@"TestNotification"])
        NSLog (@"Successfully received the test notification!");
}

- (void)viewDidLoad {
    [super viewDidLoad];

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(dismissSheet) name:UIApplicationWillResignActiveNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receiveTestNotification:) name:@"eRXReceived" object:nil];
Run Code Online (Sandbox Code Playgroud)

在正在进行通知的类中:

[UIApplication sharedApplication].applicationIconBadgeNumber = messageTotal;
[[NSNotificationCenter defaultCenter] postNotificationName:@"eRXReceived" object:self];
Run Code Online (Sandbox Code Playgroud)

但我想将对象传递messageTotal给另一个类.

cocoa-touch objective-c nsnotifications nsnotificationcenter swift

123
推荐指数
5
解决办法
10万
查看次数

对UITableView使用didSelectRowAtIndexPath或prepareForSegue方法?

我正在使用故事板,我有一个UITableView.我有一个segue设置,从我的表推送到细节VC.但是我应该使用哪种方法来处理这个问题?我必须将几个对象传递给详细视图.但我使用didSelectRowAtIndex-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender

iphone objective-c storyboard uitableview ios

100
推荐指数
2
解决办法
7万
查看次数

Xcode 4.1 GM不在Lion上安装(必须退出iTunes)?

我正在尝试在我的Lion Mac上安装Xcode 4.1 GM,但它无法正常工作.当它几乎完成时,即使它已经退出,我也会弹出以退出iTunes.因此,我唯一的选择是退出iTunes帮助程序或在活动监视器中发出警报,然后完成安装.然而,Xcode在发布时崩溃了.有任何想法吗?

xcode itunes osx-lion

14
推荐指数
1
解决办法
4634
查看次数

基础知识使用CHCSVParser简介

我正在将CHCSVParser应用到我的iPhone应用程序中(感谢Dave!)但是我真的很困惑如何使用它.我已经阅读了读书并在SO上搜索了一些问题,但仍然不能100%确定要做什么.

我有一个.CSV文件,可能有5000行数据和3-4列.

我希望这些数据作为回报,加载我的UITableView及其相应的detailViewController.

所以我假设我需要以某种方式实现API的数组方法,但任何人都可以帮助我开始吗?

csv iphone xcode parsing objective-c

14
推荐指数
1
解决办法
6288
查看次数

如何从用户获取应用程序版本号?

我想记录应用程序版本号,以便在用户发送反馈时,它将在电子邮件中.

我怎么能得到这个号码?

iphone xcode objective-c app-store

11
推荐指数
1
解决办法
1257
查看次数

如何通过Reachability检测网络变化?

我正在检查网络连接viewDidLoad使用它:

-(BOOL)reachable {
    ReachabilityDRC *r = [ReachabilityDRC reachabilityWithHostName:@"google.com"];
    NetworkStatus internetStatus = [r currentReachabilityStatus];
    if(internetStatus == NotReachable) {
        return NO;
    }
    return YES;
}
Run Code Online (Sandbox Code Playgroud)

但是我也希望在网络发生变化时收到通知,例如wifi掉线或wifi恢复,所以我可以相应地进行更改.

如何调整我的方法来做那样的事情?

iphone cocoa-touch objective-c reachability

8
推荐指数
2
解决办法
7497
查看次数

从.Plist加载数组

我正在尝试从我的.Plist中的数组加载我的数组,但它无法正常工作.

plist看起来像这样:

在此输入图像描述

这是我正在使用的代码:

NSString *path = [[NSBundle mainBundle]pathForResource:@"DiseasePropertyList" ofType:@"plist"];
NSMutableArray *rootLevel = [[NSMutableArray alloc]initWithContentsOfFile:path];
self.myArray = rootLevel;
[rootLevel release];
Run Code Online (Sandbox Code Playgroud)

iphone xcode objective-c plist nsarray

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

将核心数据添加到app时编译器错误

我正在向我的应用添加核心数据.它说,在下面的方法中Use of undeclared identifier NSSQLiteStoreType

- (NSPersistentStoreCoordinator *)persistentStoreCoordinator
{
    if (__persistentStoreCoordinator != nil)
    {
        return __persistentStoreCoordinator;
    }

    NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"tdfas.sqlite"];

    NSError *error = nil;
    __persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];
    if (![__persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:nil error:&error])
    {
        NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
        abort();
    }    

    return __persistentStoreCoordinator;
}

@property (nonatomic, retain, readonly) NSManagedObjectModel *managedObjectModel;
@property (nonatomic, retain, readonly) NSManagedObjectContext *managedObjectContext;
@property (nonatomic, retain, readonly) NSPersistentStoreCoordinator *persistentStoreCoordinator;
Run Code Online (Sandbox Code Playgroud)

iphone cocoa-touch objective-c

6
推荐指数
1
解决办法
2994
查看次数

使用NSFetchedResultsController与UISearchBar

我的应用程序中有一个UISearhBarController.它目前正在搜索在线数据库,但我正在将其更改为搜索核心数据数据库.它目前使用此代码:

- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText 
{
    if (self.billingSearchBar == searchBar) {
        [self.billingSearchController filterResultsUsingString:searchText];
    }
}

- (void)filterResultsUsingString:(NSString *)filterString 
{
    self.billingSearchText = filterString;
    NSArray *billing_codes = [self billingSearch:self.billingSearchText searchType:self.billingSearchCategory];
    self.displayedBillingSearch = billing_codes;
    self.billingSearch = billing_codes; 
    [self.tableView reloadData];
}

-(NSMutableArray*)billingSearch:(NSString*)searchString searchType:(NSString*)searchType
{
    NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@/server/20111115/60b88126/billing_search/", [self getHost]]];

    ASIFormDataRequest *request = [[[ASIFormDataRequest alloc] initWithURL:url] autorelease];
    [request setPostValue:searchString forKey:@"query"];
    [request setPostValue:searchType forKey:@"category"];

    [request startSynchronous];
    NSError *error = [request error];
    NSString *responseString;
    if (!error) {
        responseString = [request responseString];
    }

    NSMutableArray …
Run Code Online (Sandbox Code Playgroud)

iphone cocoa-touch core-data objective-c nsfetchedresultscontroller

6
推荐指数
1
解决办法
3056
查看次数

如何呈现半屏模态视图?

我有一个UIViewController,当按下一个按钮时,我想要一个半屏视图,用UIPicker向上滑动.

我在IB中使用UIPicker创建了一个UIView,还有一个带有完成/取消按钮的UIToolBar.

我怎样才能使这个半视图向上滑动,背景视图仍然显示但是暗淡或无法播放.

到目前为止我正在使用此代码:

- (void)showModalView
{
    [self.popupView setFrame:CGRectMake(0, self.view.frame.size.height, self.view.frame.size.width, self.view.frame.size.height)];
    [self.view addSubview:self.popupView];

    [UIView animateWithDuration:.2 animations:^{
        [self.popupView setFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
    }];
}
Run Code Online (Sandbox Code Playgroud)

这是一张照片:http://www.box.net/shared/static/08ji4s0f6i1b8qubrtz6.png

iphone xcode objective-c uiviewcontroller modalviewcontroller

5
推荐指数
1
解决办法
9800
查看次数