小编Swa*_*nil的帖子

Objective C和OS用户类型

有没有办法通过目标C获取当前登录的用户类型(root,admin或normal)?

我知道NSFullUserName()哪个提供用户名,但是如何检索用户类型?

谢谢.

macos cocoa objective-c

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

包括.pch文件中的公共头文件

我只是想知道,在.pch文件中包含常用/最常用的头文件是不错的做法?

例如,标题下方需要大多数文件

    #import <UIKit/UIKit.h>
    #import <Foundation/Foundation.h>
Run Code Online (Sandbox Code Playgroud)

因此,不是每个文件都应该有,在.pch文件中添加这些文件是不错的做法?

.pch文件

     #ifdef __OBJC__
     #import <UIKit/UIKit.h>
     #import <Foundation/Foundation.h>
     #import <MostlyUsed.h>
     #endif
Run Code Online (Sandbox Code Playgroud)

我发现了一些缺点,1)依赖隐藏.2)源文件无法直接复制.

如果你们提供一些意见,这将是很好的.

谢谢

objective-c ios

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

字符串到NSDate

我正在尝试将字符串转换为日期.使用了以下代码.但是错误的日期.

谢谢,

NSString *dateString = [NSString stringWithFormat:@"12-07-2011"];
//NSString *dateString = [NSString stringWithFormat:@"%d-%d-%d", selectedDate.day, selectedDate.month, selectedDate.year];
NSLog(@"%@",dateString);

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];

[dateFormatter setLocale:[NSLocale currentLocale]];
[dateFormatter setTimeZone:[NSTimeZone localTimeZone]];
[dateFormatter setDateFormat:@"dd-mm-yyyy"];

NSDate* d = [dateFormatter dateFromString:dateString];
NSLog(@"%@",d);               
                      
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Selected Date" message: [NSString stringWithFormat:@"%@",d] delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
[alert release];
Run Code Online (Sandbox Code Playgroud)

iphone objective-c nsdate

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

iPad 横向显示纵向框架和边界

我正在使用故事板开发 iPad 横向应用程序。我已经完成了以下步骤。我的应用程序是在模拟器上的横向模式中打开屏幕.. 但得到错误的框架。

  1. 来自 xcode 的用于情节提要的示例应用程序模板。
  2. 仅允许来自 info-plist 文件的横向
  3. 故事板 -> UIViewController -> 模拟矩阵 -> 将方向更改为横向
  4. 在 view controller.m 中实现以下方法

           - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
        {
         // Return YES for supported orientations
       return ((interfaceOrientation == UIInterfaceOrientationLandscapeLeft) || (interfaceOrientation == UIInterfaceOrientationLandscapeRight)); 
            } 
    
    Run Code Online (Sandbox Code Playgroud)

现在,当我获取框架和边界的 NSLog 时,它会显示我的肖像框架。

   - (void)viewDidLoad
  {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    NSLog(@"bounds ::%@",NSStringFromCGRect(self.view.bounds));
    NSLog(@"frame ::%@",NSStringFromCGRect(self.view.frame));
   }
Run Code Online (Sandbox Code Playgroud)

结果日志:

   bounds ::{{0, 0}, {748, 1024}}

   frame ::{{20, 0}, {748, 1024}}
Run Code Online (Sandbox Code Playgroud)

我错过了什么吗?

objective-c ios

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

消息传递的Objective C语法

我正在尝试以下任务:

我知道我们可以通过使用按钮点击calla方法:

[button addTarget:self action:@selector(performModalActionForButton)
forControlEvents:UIControlEventTouchUpInside];
Run Code Online (Sandbox Code Playgroud)

方法如下:

(void) performModalActionForButton:(NSString *)str
{

}
Run Code Online (Sandbox Code Playgroud)

我想在按钮单击上发送一个字符串到一个方法.我怎样才能做到这一点?

谢谢

iphone objective-c

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

UISearchBar中的清除按钮

您可以删除UISearchBar中的清除按钮(X按钮)吗?

我没有找到任何代表.有一个取消按钮.

谢谢

iphone objective-c uisearchbar ios

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

NSPredicate查询

我之前使用过NSPredicate,但出于不同的目的.但是我被困在以下场景中进行查询.

我有数组人员包含人物对象,即人物是对象数组.我需要从人员阵列中收集所有人物对象的所有名字.我知道我们可以通过for循环来实现它,但我们可以通过NSpredicate或更优化的方式来实现吗?

NSMutableArray *names;
for (int i=0; i<[persons count]; i++)
{
   [names addObject:[[persons objectAtIndex:i] names_]];
}
Run Code Online (Sandbox Code Playgroud)

iphone objective-c nspredicate

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

标签 统计

objective-c ×7

iphone ×4

ios ×3

cocoa ×1

macos ×1

nsdate ×1

nspredicate ×1

uisearchbar ×1