在我的表视图中,我必须滚动到顶部.但我不能保证第一个对象将是第0部分,第0行.可能是我的表视图将从第5节开始.
所以当我打电话时,我得到一个例外:
[mainTableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] atScrollPosition:UITableViewScrollPositionTop animated:NO];
Run Code Online (Sandbox Code Playgroud)
还有另一种滚动到表格视图顶部的方法吗?
我试图以这种方式注册本地通知的应用程序:
UIApplication.sharedApplication().registerUserNotificationSettings(UIUserNotificationSettings(forTypes: UIUserNotificationType.Alert | UIUserNotificationType.Badge, categories: nil))
Run Code Online (Sandbox Code Playgroud)
在Xcode 7和Swift 2.0中 - 我收到错误Binary Operator "|" cannot be applied to two UIUserNotificationType operands
.请帮我.
我正在尝试使用Swift更改UIButton的字体...
myButton.font = UIFont(name: "...", 10)
Run Code Online (Sandbox Code Playgroud)
但是.font
已弃用,我不知道如何更改字体.
有什么建议?
我以为我知道是什么导致了这个错误,但我似乎无法弄清楚我做错了什么.
这是我得到的完整错误消息:
Attempt to set a non-property-list object ( "<BC_Person: 0x8f3c140>" ) as an NSUserDefaults value for key personDataArray
我有一个Person
我认为符合NSCoding
协议的类,我在这个类中有这两个方法:
- (void)encodeWithCoder:(NSCoder *)coder {
[coder encodeObject:self.personsName forKey:@"BCPersonsName"];
[coder encodeObject:self.personsBills forKey:@"BCPersonsBillsArray"];
}
- (id)initWithCoder:(NSCoder *)coder {
self = [super init];
if (self) {
self.personsName = [coder decodeObjectForKey:@"BCPersonsName"];
self.personsBills = [coder decodeObjectForKey:@"BCPersonsBillsArray"];
}
return self;
}
Run Code Online (Sandbox Code Playgroud)
在应用程序的某个时刻,NSString
在BC_PersonClass
设置中,我有一个DataSave
类,我认为正在处理我的属性编码BC_PersonClass
.这是我在DataSave
课堂上使用的代码:
- (void)savePersonArrayData:(BC_Person *)personObject
{
// NSLog(@"name of the person %@", personObject.personsName); …
Run Code Online (Sandbox Code Playgroud) 在Objective-C中,可以description
向其类添加一个方法以帮助调试:
@implementation MyClass
- (NSString *)description
{
return [NSString stringWithFormat:@"<%@: %p, foo = %@>", [self class], foo _foo];
}
@end
Run Code Online (Sandbox Code Playgroud)
然后在调试器中,您可以执行以下操作:
po fooClass
<MyClass: 0x12938004, foo = "bar">
Run Code Online (Sandbox Code Playgroud)
Swift中的等价物是什么?Swift的REPL输出可能会有所帮助:
1> class MyClass { let foo = 42 }
2>
3> let x = MyClass()
x: MyClass = {
foo = 42
}
Run Code Online (Sandbox Code Playgroud)
但我想重写此行为以打印到控制台:
4> println("x = \(x)")
x = C11lldb_expr_07MyClass (has 1 child)
Run Code Online (Sandbox Code Playgroud)
有没有办法清理这个println
输出?我见过Printable
协议:
/// This protocol should be adopted by types that wish …
Run Code Online (Sandbox Code Playgroud) 有没有办法以编程方式获取我的应用程序的构建版本?我需要能够检测用户何时通过AppStore更新了应用程序,以便执行一些代码进行调整
我正在尝试获取一个格式为html的文本片段,以便在UITableViewCell中的iPhone上很好地显示.
到目前为止我有这个:
NSError* error;
NSString* source = @"<strong>Nice</strong> try, Phil";
NSMutableAttributedString* str = [[NSMutableAttributedString alloc] initWithData:[source dataUsingEncoding:NSUTF8StringEncoding]
options:@{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType,
NSCharacterEncodingDocumentAttribute: [NSNumber numberWithInt:NSUTF8StringEncoding]}
documentAttributes:nil error:&error];
Run Code Online (Sandbox Code Playgroud)
这种作品.我得到一些粗体'好'的文字!但是......它还将字体设置为Times Roman!这不是我想要的字体.我想我需要在documentAttributes中设置一些内容,但是,我无法在任何地方找到任何示例.
我正在创建一个应用程序,我想隐藏状态栏.当我测试应用程序时,状态栏会在显示启动画面时隐藏,但是一旦应用程序完全加载,状态栏就会重新出现.
我正在使用Xcode 5和iOS 7,并尝试以编程方式禁用状态栏
([[UIApplication sharedApplication] setStatusBarHidden:YES
withAnimation:UIStatusBarAnimationFade];),
Run Code Online (Sandbox Code Playgroud)
在info.plist文件中,并使用.xib文件上的属性检查器.什么都没有效果.
有任何想法吗?
我有一个简单的视图(图片的左侧),我需要创建一些覆盖(图片的右侧)到这个视图.这个叠加应该有一些不透明度,所以下面的视图仍然是部分可见的.最重要的是,这个叠加层应该在它的中间有一个圆孔,所以它不会覆盖视图的中心(见下图).
我可以轻松创建一个这样的圆圈:
int radius = 20; //whatever
CAShapeLayer *circle = [CAShapeLayer layer];
circle.path = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0,radius,radius) cornerRadius:radius].CGPath;
circle.position = CGPointMake(CGRectGetMidX(view.frame)-radius,
CGRectGetMidY(view.frame)-radius);
circle.fillColor = [UIColor clearColor].CGColor;
Run Code Online (Sandbox Code Playgroud)
像这样的"完整"矩形覆盖:
CAShapeLayer *shadow = [CAShapeLayer layer];
shadow.path = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, view.bounds.size.width, view.bounds.size.height) cornerRadius:0].CGPath;
shadow.position = CGPointMake(0, 0);
shadow.fillColor = [UIColor grayColor].CGColor;
shadow.lineWidth = 0;
shadow.opacity = 0.5;
[view.layer addSublayer:shadow];
Run Code Online (Sandbox Code Playgroud)
但我不知道如何将这两个层组合在一起,以便创建我想要的效果.任何人?我已经尝试了所有的东西......非常感谢你的帮助!
我正在寻找一种方法来使用Swift代码访问我的应用程序中的SQLite数据库.
我知道我可以在Objective C中使用SQLite Wrapper并使用桥接头,但我宁愿能够完全在Swift中完成这个项目.有没有办法做到这一点,如果是这样,有人可以指向我的参考,显示如何提交查询,检索行等?