Я пытался загрузить теги taggable_friends из Facebook, мне удалось их получить, но не удалось загрузить в UItableView. Я попытался получить запрос методом «ячейка для строки в», но он меняет порядок или обновляется каждые 2–3 секунды. Я пытался объявить массивы и сохранить имена и изображения профилей, но произошел сбой.
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "friendCell", for: indexPath) as! friendstvc
// The first try
/*FBSDKGraphRequest(graphPath: "me/taggable_friends?limit=5000", parameters: nil).start { (connection, result, error) in
if error != nil
{
print(error?.localizedDescription ?? "")
cell.friendName.text = ""
return
}
let dic = result as! Dictionary
let data = dic["data"] as! NSArray
if let name = dic["name"]
{
print(name as! String)
}
let valuedict = data[indexPath.row] as! Dictionary
let id = valuedict["id"] as! String
let name = valuedict["name"] as! String
cell.friendName.text = name
cell.profpic.profileID = id
}*/
// The second try
cell.friendName.text = friendnames[indexPath.row] // crashes here
cell.profpic.image = friendpictures[indexPath.row]
return cell
}
Приведенный ниже метод вызывается в viewDidLoad со второй попытки
// for the second try
func loadtaggableFriends()
{
// Called in the viewDidLoad
FBSDKGraphRequest(graphPath: "me/taggable_friends?limit=5000", parameters: nil).start { (connection, result, error) in
if error != nil{
print(error?.localizedDescription ?? "")
return
}
let dic = result as! Dictionary
let data = dic["data"] as! NSArray
if let name = dic["name"]
{
print(name as! String)
}
print(data.count)
for i in 0...data.count - 1
{
let valuedict = data as! Dictionary
let name = valuedict["name"] as! String
var dataurl: Data?
if let picture = valuedict["picture"] as? NSDictionary, let data = picture["data"] as? NSDictionary, let url = data["url"] as? String
{
let loadurl = URL(string: url)
dataurl = try? Data(contentsOf: loadurl!)
}
friendnames.append(name)
friendpictures.append(UIImage(data: dataurl!)!)
}
}
}
// declaring the arrays
var friendnames = [String]()
var friendpictures = [UIImage]()
Подробнее здесь: https://stackoverflow.com/questions/483 ... table-view
Swift Facebook отмечает друзей в uitableview ⇐ IOS
Программируем под IOS
-
Anonymous
1736364698
Anonymous
Я пытался загрузить теги taggable_friends из Facebook, мне удалось их получить, но не удалось загрузить в UItableView. Я попытался получить запрос методом «ячейка для строки в», но он меняет порядок или обновляется каждые 2–3 секунды. Я пытался объявить массивы и сохранить имена и изображения профилей, но произошел сбой.
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "friendCell", for: indexPath) as! friendstvc
// The first try
/*FBSDKGraphRequest(graphPath: "me/taggable_friends?limit=5000", parameters: nil).start { (connection, result, error) in
if error != nil
{
print(error?.localizedDescription ?? "")
cell.friendName.text = ""
return
}
let dic = result as! Dictionary
let data = dic["data"] as! NSArray
if let name = dic["name"]
{
print(name as! String)
}
let valuedict = data[indexPath.row] as! Dictionary
let id = valuedict["id"] as! String
let name = valuedict["name"] as! String
cell.friendName.text = name
cell.profpic.profileID = id
}*/
// The second try
cell.friendName.text = friendnames[indexPath.row] // crashes here
cell.profpic.image = friendpictures[indexPath.row]
return cell
}
Приведенный ниже метод вызывается в viewDidLoad со второй попытки
// for the second try
func loadtaggableFriends()
{
// Called in the viewDidLoad
FBSDKGraphRequest(graphPath: "me/taggable_friends?limit=5000", parameters: nil).start { (connection, result, error) in
if error != nil{
print(error?.localizedDescription ?? "")
return
}
let dic = result as! Dictionary
let data = dic["data"] as! NSArray
if let name = dic["name"]
{
print(name as! String)
}
print(data.count)
for i in 0...data.count - 1
{
let valuedict = data[i] as! Dictionary
let name = valuedict["name"] as! String
var dataurl: Data?
if let picture = valuedict["picture"] as? NSDictionary, let data = picture["data"] as? NSDictionary, let url = data["url"] as? String
{
let loadurl = URL(string: url)
dataurl = try? Data(contentsOf: loadurl!)
}
friendnames.append(name)
friendpictures.append(UIImage(data: dataurl!)!)
}
}
}
// declaring the arrays
var friendnames = [String]()
var friendpictures = [UIImage]()
Подробнее здесь: [url]https://stackoverflow.com/questions/48380598/swift-facebook-taggable-friends-in-uitable-view[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия