小编han*_*Dev的帖子

如何将NSDictionary数据导入UITableView

我有2个NSArrays,我试图在NSDictionary中链接在一起,以便每个providerName都有一个与之关联的providerId.

我希望使用两个数组相互关联,self.providersDict = [NSDictionary dictionaryWithObjects:providerName forKeys:providerId];然后将providerName显示为表格单元格标题,将id显示为表格单元格字幕.

目前我无法获取UITable上显示的数据,甚至无法使用以下方式注销字典:

   for (id key in self.providersDict) {
    NSLog(@"key: %@, value: %@", key, [self.providersDict objectForKey:key]);
}
Run Code Online (Sandbox Code Playgroud)

在.h中声明:

NSArray *providerName;
NSArray *providerId;

@property (nonatomic, strong) NSDictionary *providersDict;
Run Code Online (Sandbox Code Playgroud)

并在viewDidLoad中:

    providerName = [NSArray arrayWithObjects:@"provider1", @"provider2", @"provider3", nil];
    providerId = [NSArray arrayWithObjects:@"1", @"2", @"3", nil];

    self.providersDict = [NSDictionary dictionaryWithObjects:providerName
                                                           forKeys:providerId];
Run Code Online (Sandbox Code Playgroud)

UITable方法:

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [[self.providersDict allKeys] count];
}


-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{



 static NSString *unifiedID = @"aCellID";
    UITableViewCell *cell …
Run Code Online (Sandbox Code Playgroud)

iphone objective-c nsdictionary uitableview ios

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

无法识别的选择器从UIButton发送到实例错误消息

我有一个以编程方式添加到tableview的UIButton.问题是,当它被触摸时,我遇到发送到实例错误消息的无法识别的选择器.

    UIButton *alertButton = [UIButton buttonWithType:UIButtonTypeInfoDark];     
    [alertButton addTarget:self.tableView action:@selector(showAlert:) 
          forControlEvents:UIControlEventTouchUpInside];
    alertButton.frame = CGRectMake(220.0, 20.0, 160.0, 40.0);

    [self.tableView addSubview:alertButton];
Run Code Online (Sandbox Code Playgroud)

这是触摸InfoDark UIButton时我想要触发的警报方法:

- (void) showAlert {
        UIAlertView *alert = 
         [[UIAlertView alloc] initWithTitle:@"My App" 
                                    message: @"Welcome to ******. \n\nSome Message........" 
                                   delegate:nil 
                          cancelButtonTitle:@"Dismiss" 
                          otherButtonTitles:nil];
        [alert show];
        [alert release];
}
Run Code Online (Sandbox Code Playgroud)

谢谢你的帮助.

iphone objective-c uibutton ios unrecognized-selector

5
推荐指数
2
解决办法
9282
查看次数

从iPhone应用程序中启动指南针应用程序

我正在尝试这样的东西从我的应用程序中启动指南针:

    NSString *stringURL = @"compass://";
    NSURL *url = [NSURL URLWithString:stringURL];
    [[UIApplication sharedApplication] openURL:url];
Run Code Online (Sandbox Code Playgroud)

有没有人知道用于启动罗盘应用程序的正确网址?

http://wiki.akosma.com/IPhone_URL_Schemes - 我正在使用它作为参考,但没有发布指南针.

谢谢你的帮助.

iphone objective-c ios

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

增加核心数据模型字段的值

我正在使用以下代码增加模型字段的数量:

- (IBAction) counterButton: (id) sender {
    [model.amount++ stringValue];
}
Run Code Online (Sandbox Code Playgroud)

它在我升级Xcode之前工作正常.从那时起,我一直收到以下错误:

"Arithmetic on pointer to Interface 'NSNumber'. which is not a constant size in non-fragile ABI"
Run Code Online (Sandbox Code Playgroud)

当代码工作时,每次触摸UIButton时,它会将值递增1.

任何帮助将不胜感激.谢谢

iphone core-data objective-c ios

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

如何为MFSideMenu类中的某些视图控制器禁用平移模式?

我在我的项目中使用来自github链接的MFSideMenu .它正在工作,但是我想在某个viewcontroller中禁用它.

我在viewcontroller中添加了它,但它没有禁用panMode:

#import "MFSideMenuContainerViewController.h"

-(void) viewWillAppear:(BOOL)animated {

    MFSideMenuContainerViewController *sideMenu = [[MFSideMenuContainerViewController alloc] init];

    sideMenu.panMode = 0;

}
Run Code Online (Sandbox Code Playgroud)

我的计划是在viewDidDisappear方法中重新启用panmode.

MFSideMenuContainerViewController.m如果我添加self.panMode = 0; 到文件中的FYI - (void)setDefaultSettings {self.panMode = 0;}会禁用菜单平移,除非它为整个应用程序禁用它当然.

我一定不能正确引用MFSideMenuContainerViewController属性panmode.

在我的AppDelegate中:

.H

@property (nonatomic, strong) MFSideMenuContainerViewController *container;
Run Code Online (Sandbox Code Playgroud)

.M

  MFSideMenuContainerViewController *container = [MFSideMenuContainerViewController
                                                    containerWithCenterViewController:self.navController
                                                    leftMenuViewController:nil
                                                    rightMenuViewController:rightSideMenuController];

    self.window.rootViewController = container;
Run Code Online (Sandbox Code Playgroud)

谢谢你的帮助

iphone objective-c uiviewcontroller ios

5
推荐指数
2
解决办法
3771
查看次数

CGRect图像大小调整

我正在使用CGRect来显示图像.我希望CGRect在没有指定的情况下使用图像的宽度和高度.

这可以:

CGRectMake(0.0f, 40.0f, 480.0f, 280.0f);
Run Code Online (Sandbox Code Playgroud)

变成这样:

CGRectMake(0.0f, 40.0f, myImage.width, myImage.height);
Run Code Online (Sandbox Code Playgroud)

指定参数时,某些图像会失真.

这是代码:

CGRect myImageRect = CGRectMake(0.0f, 40.0f, 480.0f, 280.0f);
UIImageView *myImage = [[UIImageView alloc] initWithFrame:myImageRect];
[myImage setImage:[UIImage imageNamed:recipe.img]];
Run Code Online (Sandbox Code Playgroud)

谢谢你的帮助.

objective-c uiimage ios

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

Analyzer报告以下代码泄漏

Analyzer报告以下代码可能存在内存泄漏.任何人都可以对此有所了解吗?我正在发布已经分配的注释.

  -(AddressAnnotation *)addAdress:(NSString*)placeTitle SubTitle:(NSString*)placeSubTitle Coordinate:(CLLocationCoordinate2D)coord withId:(NSInteger) placeId{
        AddressAnnotation *annotation = [[AddressAnnotation alloc] initWithCoordinate:coord];
        annotation.placeTitle = placeTitle;
        annotation.placeSubTitle = placeSubTitle;
        annotation.museumId = placeId;
        [mapView addAnnotation:annotation]; 
        return annotation;

        [annotation release];
    }
Run Code Online (Sandbox Code Playgroud)

iphone memory-management objective-c analyzer ios

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

如何从NSDate倒计时并以小时和分钟显示它

我正在尝试从NSDate倒计时,并在几小时和几分钟内显示它.像这样:1小时:18分钟

目前我的日期正在更新为UILabel并倒计时但显示如下:

计时器倒计时标签

这是我正在使用的代码.startTimer方法和updateLabel方法

 - (void)startTimer {
        // Set the date you want to count from

    // convert date string to date then set to a label
    NSDateFormatter *dateStringParser = [[NSDateFormatter alloc] init];
    [dateStringParser setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.000Z"];

    NSDate *date = [dateStringParser dateFromString:deadlineDate];

    NSDateFormatter *labelFormatter = [[NSDateFormatter alloc] init];
    [labelFormatter setDateFormat:@"HH-dd-MM-yyyy"];

    NSDate *countdownDate = [[NSDate alloc] init];

    countdownDate = date; 

    // Create a timer that fires every second repeatedly and save it in an ivar
    NSTimer *timer = [[NSTimer alloc] init];

    timer = [NSTimer …
Run Code Online (Sandbox Code Playgroud)

objective-c nsdate nstimer ios

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

如何使用NSSortDescriptor对NSMutableArray进行排序

我正在使用以下NSSortDescriptor代码对数组进行排序.我目前按价格排序,但也希望对价格加以限制.是否有可能按价格排序,但仅显示价格低于100?

NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc]
                                        initWithKey: @"price" ascending: YES];

NSMutableArray *sortedArray = (NSMutableArray *)[self.displayItems
                                                     sortedArrayUsingDescriptors: [NSArray arrayWithObject:sortDescriptor]];

[self setDisplayItems:sortedArray];

[self.tableView reloadData];
Run Code Online (Sandbox Code Playgroud)

cocoa objective-c nssortdescriptor

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

AVAudioPlayer - 在UILabel上显示倒数计时器

我有一个倒数计时器,显示音轨上剩余的秒数.由于某种原因,倒计时不是以1秒的间隔计数,而是在第一次计数时为2秒,在下一次计数时为1秒.(它正在计算这种模式 - 它会跳2秒,然后一遍又一遍).

这是我的代码:

// display current time left on the track
- (void)updateTimeLeft {
    NSTimeInterval timeLeft = self.player.duration - self.player.currentTime;

    // update your UI with timeLeft
    self.timeDisplay.text = [NSString stringWithFormat:@"%.2f", timeLeft / 60];

}
Run Code Online (Sandbox Code Playgroud)

这是我的NSTimer:

NSTimer * myTimer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(updateTimeLeft) userInfo:nil repeats:YES];
Run Code Online (Sandbox Code Playgroud)

谢谢你的帮助.

iphone objective-c nstimer avaudioplayer ios

3
推荐指数
1
解决办法
3205
查看次数