我有一个Data类型的变量fileData,我很难找到如何打印这个的大小.
在过去的NSData中,您将打印长度,但无法使用此类型执行此操作.
如何在Swift 3.0中打印数据的大小?
我有一个实体只在一个部分中显示在表视图中.该实体有两个属性,workoutName和trainingLevel.两者都是字符串类型.训练水平由3种类型组成:1,2,3(trainingLevel =(整数16或字符串类型?哪个是理想的?)我想将表分成三个部分,每个部分包含相应训练级别的条目.
我该怎么做呢?我目前使用的代码如下:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return self.workoutType.workouts.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell =
[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle
reuseIdentifier:CellIdentifier];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
WorkoutSet *workoutSet = [self.fetchedResultsController objectAtIndexPath:indexPath];
cell.textLabel.text = workoutSet.workoutName;
cell.detailTextLabel.text = [NSString …Run Code Online (Sandbox Code Playgroud) https://developer.apple.com/library/ios/releasenotes/DataManagement/WhatsNew_CoreData_iOS/
我在禁用日记模式时遇到问题.
我的代码是:
static NSManagedObjectContext *managedObjectContext(){
static NSManagedObjectContext *context = nil;
if (context != nil) {
return context;
}
NSString * const NSSQLitePragmasOption;
NSSQLitePragmasOption : @{ @"journal_mode" : @"DELETE" };
@autoreleasepool {
context = [[NSManagedObjectContext alloc] init];
NSPersistentStoreCoordinator *coordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:managedObjectModel()];
[context setPersistentStoreCoordinator:coordinator];
NSString *STORE_TYPE = NSSQLiteStoreType;
NSString *path = @"ExerciseDB";
NSURL *url = [NSURL fileURLWithPath:[path stringByAppendingPathExtension:@"sqlite"]];
NSError *error;
NSPersistentStore *newStore = [coordinator addPersistentStoreWithType:STORE_TYPE configuration:nil URL:url options:NSSQLitePragmasOption error:&error];
if (newStore == nil) {
NSLog(@"Store Configuration Failure %@", ([error …Run Code Online (Sandbox Code Playgroud) 当我在我的设备上运行我的应用程序时,不会显示图像.
在模拟器模式下,显示图像.
当我在设备上运行应用程序时,我没有收到任何复制错误消息或任何其他类型的警报.
有任何想法吗?
此外,所讨论的图像位于分页UI Scroll视图中,该视图使用以下教程进行编码:
http://www.raywenderlich.com/10518/how-to-use-uiscrollview-to-scroll-and-zoom-content
本教程中使用UIScrollView部分进行分页.
谢谢
如果可以在一个ViewController中拥有多个uiTableView,我就会徘徊.
例如:
tableView1和tableView2在一个视图控制器中.
初始启动视图控制器,应禁用tableView2并且不可见.
tableView1应该显示与之关联的数据.
当用户从tableView1中选择一行时,它应该显示与tableView2中所选行相对应的数据.
仍应启用tableView1,如果用户选择另一行,则tableView2的内容也应分别更改.
感谢您提供的任何帮助或指导.:)
我有一个 JSON 填充了供应商列表。将其作为可在类中轻松访问并可通过项目传递的实例的最佳和最有效方法是什么。我正在考虑使用 struct ,因为我以前没有使用过它们。它比使用 Object 更好吗?
下面我有我的结构。
struct Vendor {
let name: String
let latitude: Double
let longitude: Double
init(dictionary: [String: Any]) {
self.name = dictionary["name"] as? String ?? ""
self.latitude = dictionary["Lat"] as? Double ?? 0.0
self.longitude = dictionary["Lng"] as? Double ?? 0.0
}
init?(data: Data) {
guard let json = (try? JSONSerialization.jsonObject(with: data)) as? [String: Any] else { return nil }
self.init(dictionary: json)
}
init?(json: String) {
self.init(data: Data(json.utf8))
}
Run Code Online (Sandbox Code Playgroud)
}
我的问题是如何从这种结构类型的 JSON 创建一个数组。
谢谢
我目前正在开发使用情节提要开发的应用程序。
我试图在开始之前以编程方式将视图控制器添加到分页滚动视图中,然后再在情节提要中添加其他2个视图。
添加了视图控制器,但宽度稍大,并进入了中间视图。
let vc = Vc()
scrollView.addSubview(vc.view)
Run Code Online (Sandbox Code Playgroud)