小编P.J*_*iya的帖子

UITableview:如何禁用某些行而不是其他行的选择

我正在显示tableview从XML解析的组内容.我想禁用它上面的click事件(我根本不应该单击它)该表包含两个组.我想禁用第一组的选择,但不禁用第二组.单击第二组的第一行navigates到我的管player view.

如何才能选择特定的组或行?

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{
    if(indexPath.section!=0)
    if(indexPath.row==0)    

    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:tubeUrl]];   
}
Run Code Online (Sandbox Code Playgroud)

谢谢.

iphone objective-c uitableview ios

284
推荐指数
12
解决办法
21万
查看次数

在UIViewController上显示clearColor UIViewController

我有一个UIViewController视图作为另一个UIViewController视图顶部的子视图/模态,例如子视图/模态应该是透明的,并且任何添加到子视图的组件都应该是可见的.问题是我有子视图显示黑色背景而不是有clearColor.我试图制作UIView一个clearColor而不是黑色背景.有人知道它有什么问题吗?任何建议表示赞赏.

FirstViewController.m

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"SecondViewController"];

[vc setModalPresentationStyle:UIModalPresentationFullScreen];
[self presentModalViewController:vc animated:NO];  
Run Code Online (Sandbox Code Playgroud)

SecondViewController.m

- (void)viewDidLoad 
{
     [super viewDidLoad];
     self.view.opaque = YES;
     self.view.backgroundColor = [UIColor clearColor];
}
Run Code Online (Sandbox Code Playgroud)

决议:我解决了问题.它适用于iPhone和iPad.没有黑色背景的模态视图控制器只是clearColor/transparent.我需要改变的唯一一件事是我换成UIModalPresentationFullScreenUIModalPresentationCurrentContext.这有多简单啊!

FirstViewController.m

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"SecondViewController"];
vc.view.backgroundColor = [UIColor clearColor];
self.modalPresentationStyle = UIModalPresentationCurrentContext;
[self presentViewController:vc animated:NO completion:nil];
Run Code Online (Sandbox Code Playgroud)

注意:如果您使用以下modalPresentationStyle财产navigationController:

FirstViewController.m

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil]; …
Run Code Online (Sandbox Code Playgroud)

iphone objective-c storyboard uiviewcontroller ios

147
推荐指数
7
解决办法
9万
查看次数

检查子视图是否在视图中

我在做一个应用程序,我一个子视图添加到使用视图addSubview:IBAction.以同样的方式,当IBAction再次触摸带有该按钮的按钮时,应该调用removeFromSuperview添加在该子视图上的子视图IBAction:

PSEUDO CODE

-(IBAction)showPopup:(id)sender 
{
    System_monitorAppDelegate *delegate = (System_monitorAppDelegate *)[[UIApplication sharedApplication] delegate];
    UIView *rootView = delegate.window.rootViewController.view;

    if([self popoverView] is not on rootView) 
    { 
        [rootView addSubview:[self popoverView]];
    } 
    else 
    {
        [[self popoverView] removeFromSuperview];
    }

}
Run Code Online (Sandbox Code Playgroud)

cocoa-touch uikit uiview ios

93
推荐指数
3
解决办法
8万
查看次数

取消UILocalNotification

我的UILocalNotification有问题.

我正在使用我的方法安排通知.

- (void) sendNewNoteLocalReminder:(NSDate *)date  alrt:(NSString *)title
{
    // some code ...
    UILocalNotification *localNotif = [[UILocalNotification alloc] init]; 

    if (localNotif == nil)  
        return;

    localNotif.fireDate = itemDate; 
    localNotif.timeZone = [NSTimeZone defaultTimeZone];
    localNotif.alertAction = NSLocalizedString(@"View Details", nil); 
    localNotif.alertBody = title;
    localNotif.soundName = UILocalNotificationDefaultSoundName; 
    localNotif.applicationIconBadgeNumber = 0;

    NSDictionary *infoDict = [NSDictionary dictionaryWithObject:stringID forKey:@"id"]; 
    localNotif.userInfo = infoDict; 

    [[UIApplication sharedApplication] scheduleLocalNotification:localNotif]; 
    [localNotif release];
}
Run Code Online (Sandbox Code Playgroud)

它工作正常,我正确收到通知.问题是我应该取消通知.我正在使用这种方法.

- (void) deleteNewNoteLocalReminder:(NSString*) reminderID noteIDe:(NSInteger)noteIDE
{
    [[UIApplication sharedApplication] cancelLocalNotification:(UILocalNotification *)notification ????  
}
Run Code Online (Sandbox Code Playgroud)

我不知道该怎么做,但我的问题是:

我如何知道应删除哪个UILocalNotification对象?
有没有办法列出所有通知?

我唯一拥有的是我应删除的提醒ID.
我正在考虑将UILocalNotification对象保存在我的"Note"对象中并以此方式获取,当我保存到我的SQLite数据库时序列化对象等等......是否有更聪明的方法?

iphone notifications cocoa-touch ios4

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

以编程方式创建UITableView

我在Xcode 4.6中有一个使用故事板的应用程序.我向视图控制器类添加了一个UITableView,它按预期工作.但是,当我尝试在故事板中删除UITableView并以编程方式将其添加回同一个类时,我遇到了两个具体问题:

1)虽然我将UITableViewCell类型设置为字幕类型,但不再显示详细信息标签.

2)当我选择一个单元格时应该发生的segue,并且甚至没有调用准备segue,表示当选择单元格时没有消息被发送到表视图.

这是相关代码:

@interface StatsTableViewController () <UITableViewDataSource, UITableViewDelegate>
@property (strong, nonatomic) UITableView *tableView;

@end

@implementation StatsTableViewController

-(UITableView *)makeTableView
{
    CGFloat x = 0;
    CGFloat y = 50;
    CGFloat width = self.view.frame.size.width;
    CGFloat height = self.view.frame.size.height - 50;
    CGRect tableFrame = CGRectMake(x, y, width, height);

    UITableView *tableView = [[UITableView alloc]initWithFrame:tableFrame style:UITableViewStylePlain];

    tableView.rowHeight = 45;
    tableView.sectionFooterHeight = 22;
    tableView.sectionHeaderHeight = 22;
    tableView.scrollEnabled = YES;
    tableView.showsVerticalScrollIndicator = YES;
    tableView.userInteractionEnabled = YES;
    tableView.bounces = YES;

    tableView.delegate = self;
    tableView.dataSource = self;

    return …
Run Code Online (Sandbox Code Playgroud)

xcode objective-c uitableview ios

45
推荐指数
3
解决办法
11万
查看次数

如何使用UIStepper

我正在努力UIStepper增加或减少一个整数,但" - "和"+"都会增加整数!如何识别"+"和" - "按钮?

UIStepper头文件中有两个UIButtons:

UIButton *_plusButton;
UIButton *_minusButton;
Run Code Online (Sandbox Code Playgroud)

例如 :

- (IBAction)changeValue:(id)sender 
{        
    UIStepper *stepper = (UIStepper *) sender;

    stepper.maximumValue = 10;
    stepper.minimumValue = 0;      
    if (stepper)
    {
        integer++;
        [label setText:[NSString stringWithFormat:@"%d",integer]];
     }
     else
     { 
         integer--;
         [label setText:[NSString stringWithFormat:@"%d",integer]];
     }

}
Run Code Online (Sandbox Code Playgroud)

objective-c ios uistepper

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

如何在不使用AudioSessionSetProperty的情况下将音频路由到扬声器?

作为AudioSessionSetProperty有可能成为deprecated,我想找到的代码示例如何路由音频到speaker使用其他手段.

以前我做过以下事情:

-(void)setSpeakerEnabled
{
    debugLog(@"%s",__FUNCTION__);
    UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker;

    AudioSessionSetProperty (
                         kAudioSessionProperty_OverrideAudioRoute,
                         sizeof (audioRouteOverride),
                         &audioRouteOverride
                         );
}
Run Code Online (Sandbox Code Playgroud)

试图获得相同的结果,但without callAudioSessionSetProperty.

objective-c ios avaudiosession

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

在外部水龙头上关闭模态视图表单控制器

我将一个模态视图控制器呈现为一个表单,并在单击取消按钮(即一个条形按钮项目)时将其解除.当我在该视图之外点击时,我需要忽略它.请帮我一个参考.注意:我的模态视图控制器带有导航控制器.

@cli_hlt,@ Bill Brasky感谢您的回答.当在作为表单的模态视图之外发生敲击时,我需要忽略它.我在下面粘贴我的代码.

-(void)gridView:(AQGridView *)gridView didSelectItemAtIndex:(NSUInteger)index  
{        
    if(adminMode) 
    {
        CHEditEmployeeViewController *editVC = [[CHEditEmployeeViewController alloc] initWithNibName:@"CHEditEmployeeViewController" bundle:nil];
        editVC.delegate = self;
        editVC.pickedEmployee = employee;
        editVC.edit = TRUE;
        editVC.delegate = self;
        UINavigationController *navigationController = [[UINavigationController alloc]initWithRootViewController:editVC];
        navigationController.modalPresentationStyle = UIModalPresentationFormSheet;
        [self presentModalViewController:navigationController animated:YES];

        return;
    }   //the above code is from the view controller which presents the modal     view. Please look at the below code too which is from my modal view controller. Please guide me in a proper way.   -(void)tapGestureRecognizer {

    UITapGestureRecognizer *recognizer …
Run Code Online (Sandbox Code Playgroud)

xcode objective-c uinavigationcontroller modalviewcontroller

32
推荐指数
9
解决办法
3万
查看次数

如何从NSDictionary中删除对象

嗨,我有一个NSdictionary我在其中添加一个关键"国家"的数组.现在我把这个字典的值放到数组中并按照alpahbatical顺序对数组进行排序.现在我想将这个数组添加到我的字典中(我想用新的排序数组更新我的字典并从中删除旧数组). ....... 这该怎么做

我的代码如下

NSArray *countriesToLiveInArray = [NSArray arrayWithObjects:@"Iceland", @"Greenland", @"Switzerland", @"Norway", @"New Zealand", @"Greece", @"Italy", @"Ireland", nil];
NSDictionary *countriesToLiveInDict = [NSDictionary dictionaryWithObject:countriesToLiveInArray forKey:@"Countries"];


NSArray *tmpary = [countriesToLiveInDict valueForKey:@"Countries"];
NSLog(@"ary value is  %@",ary);
NSArray *sortedArray = [tmpary sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
NSLog(@"sortedArray is %@",sortedArray);
Run Code Online (Sandbox Code Playgroud)

在这里,我想删除countriesToLiveInArray并将其替换为具有相同键值的sortedArray,即国家/地区提前感谢..

iphone objective-c nsdictionary ios

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

取消iOS 7后滑动手势后,导航堆栈变得无法使用

我遇到了一个问题,我的导航控制器在启动然后取消新的iOS 7后滑动手势后变得无法使用.

一些相关信息:

  • 我的应用程序有一个包含各种活动页面的主页.
  • 主页隐藏viewWillAppear中的导航栏
  • 主页取消隐藏viewWillDisappear中的导航栏

    -(void) viewWillAppear:(BOOL)animated
    {
        [super viewWillAppear:animated];
    
        // Let's hide the navbar when we show the home view
        [self.navigationController setNavigationBarHidden:YES];
        …
    }
    
    -(void) viewDidDisappear:(BOOL)animated 
    {
        [super viewDidDisappear:animated];
    
        // Let's hide the navbar when we show the home view
        [self.navigationController setNavigationBarHidden:NO];
    }
    
    Run Code Online (Sandbox Code Playgroud)

当用户点击主页上的活动图标时,活动的视图控制器被推送到堆栈上.

如果用户开始在iOS中使用新的后滑动手势,但随后停止手势(即决定不返回),一切看起来都不错.但是,如果用户导致另一个视图控制器被推到导航堆栈上,那么唠叨条就会变得无法使用,并且用户无法从当前视图控制器导航回来.

笔记

  • 它只在我显示/隐藏导航栏时发生
  • 我仍然可以慢慢地执行后退手势,只要我不取消手势,一切都会正常工作
  • 导航栏似乎可以工作,但点击后退按钮不会弹出视图控制器.

uinavigationbar uinavigationcontroller ios ios7

26
推荐指数
1
解决办法
5488
查看次数